[R] xtable caption knitr

Ulises M. Alvarez uma at sophie.unam.mx
Tue Feb 24 16:17:07 CET 2015


On 02/24/2015 05:16 AM, AURORA GONZALEZ VIDAL wrote:
> I have a problem with the caption option on the xtable function.
>
> Using Rmarkdown, knitr generates correctly a pdf when I write something
> like this:
>
> ```{r xtable, results="asis"}
> library( xtable )
> variableName  <- c( "V03_1" )
> age <- c( rep(1,10),rep(2,10),rep(3,10) )
> gender <- c( rep("m",15), rep("f",15) )
>
> df <- data.frame( age, gender )
>
> t     <- xtable( df, caption = "hello" )
> print( t, caption.placement = 'top',comment = FALSE )
> ```
>
> But if I change to
>
> t     <- xtable(df, caption = variableName)
>
> wich is what I really want it retuns a pandoc error

Hello:

It is, indeed, the underscore in the variable name. You should define it as:

variableName  <- c("V03\\_1")

And now:

t <- xtable(df, caption = variableName)
print(t, caption.placement = 'top',comment = FALSE)

Will work.

-- 
Ulises M. Alvarez
http://sophie.unam.mx/



More information about the R-help mailing list