I hesitate to post this because it doesn't add much to the linked question that you shared...
Just change llply(...)
to l_ply
and make sure that the chunk options for the xtable
s is set to something like <<echo=FALSE, results='asis'>>=
I was able to create an Rnw file with the following content that works just fine:
\documentclass{article}
\begin{document}
<<echo=FALSE>>=
library(plyr)
library(xtable)
Data <- data.frame(a=rbinom(100,1,0.5), b=rbinom(100,1,0.3), c=rbinom(100,1,0.6))
combos <- combn(ncol(Data),2)
TabelFn <- function(x) {
Table <- addmargins(table(Data[, x[1]], Data[, x[2]]))
return(Table)
}
Table <- alply(.data=combos, .margins=2, .fun=TabelFn, .expand=TRUE)
@
<<echo=FALSE, results='asis'>>=
l_ply(Table, function(x) { print(xtable(x)) })
@
\end{document}
A couple of points to note:
$
is a special character in LaTeX, so having them in your output will create problemsalply
andllply
will show the output, but you don't want that, so you should use the_
versions (a_ply
andl_ply
) when appropriate. From the help file tol_ply
, All output is discarded. This is useful for functions that you are calling purely for their side effects like displaying plots or saving output.