xtable caption knitr

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

xtable caption knitr

AURORA GONZALEZ VIDAL
Dear all,
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:

! Missing $ inserted.
<inserted text>
                $
l.112 \caption{V03_1}

pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43

I don't know why because variableName is also a character variable!

Any idea? Thank you very much!


------
Aurora González Vidal

Sección Apoyo Estadístico.
Servicio de Apoyo a la Investigación (SAI).
Vicerrectorado de Investigación.
Universidad de Murcia
Edif. SACE . Campus de Espinardo.
30100 Murcia

@. [hidden email]
T. 868 88 7315
F. 868 88 7302
www.um.es/sai
www.um.es/ae

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: xtable caption knitr

Michael Dewey
Dear Aurora

I suspect the underscore character in your variable name is the problem.


On 24/02/2015 11:16, AURORA GONZALEZ VIDAL wrote:

> Dear all,
> 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:
>
> ! Missing $ inserted.
> <inserted text>
>                  $
> l.112 \caption{V03_1}
>
> pandoc: Error producing PDF from TeX source
> Error: pandoc document conversion failed with error 43
>
> I don't know why because variableName is also a character variable!
>
> Any idea? Thank you very much!
>
>
> ------
> Aurora González Vidal
>
> Sección Apoyo Estadístico.
> Servicio de Apoyo a la Investigación (SAI).
> Vicerrectorado de Investigación.
> Universidad de Murcia
> Edif. SACE . Campus de Espinardo.
> 30100 Murcia
>
> @. [hidden email]
> T. 868 88 7315
> F. 868 88 7302
> www.um.es/sai
> www.um.es/ae
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2015.0.5645 / Virus Database: 4299/9172 - Release Date: 02/24/15
>

--
Michael
http://www.dewey.myzen.co.uk

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: xtable caption knitr

Ulises M. Alvarez-3
In reply to this post by AURORA GONZALEZ VIDAL
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/

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.