Xtable in .Rmd then knit as pdf in rstudio shows% comments

I am making a PDF file using Rstudio 'knit PDF' when writing an R Markdown (.Rmd) file.

When creating a table using the xtable function, text commented in latex using% is displayed in pdf. This problem disappears when knitting a .Rnw file using latex and R.

The following is an example .Rmd file for knitting as a PDF and the equivalent .Rnw file for knitting (such as pdf).

Their PDF results are identical except for one line. Above the table, the following is displayed:

% latex table generated in R 3.1.0 using the package xxt 1.7-7% cf aug. 06 19:06:37 2014

MarkdownFile.Rmd

--- output: pdf_document --- ```{r, results='asis'} library(xtable) xtable(summary(cars)) ``` 

SweaveFile.Rnw

 \documentclass{article} \begin{document} <<r, results='asis'>>= library(xtable) xtable(summary(cars)) @ \end{document} 

The actual output of the xtable(summary(cars)) expression in r is given below. You can see the first two lines, starting with % . The difference is that the .Rnw file hides them, and the .Rmd files do not.

 % latex table generated in R 3.1.0 by xtable 1.7-3 package % Wed Aug 06 19:33:18 2014 \begin{table}[ht] \centering \begin{tabular}{rll} \hline & speed & dist \\ \hline 1 & Min. : 4.0 & Min. : 2.00 \\ 2 & 1st Qu.:12.0 & 1st Qu.: 26.00 \\ 3 & Median :15.0 & Median : 36.00 \\ 4 & Mean :15.4 & Mean : 42.98 \\ 5 & 3rd Qu.:19.0 & 3rd Qu.: 56.00 \\ 6 & Max. :25.0 & Max. :120.00 \\ \hline \end{tabular} \end{table} 

I assume the problem is that the linked .Rmd file does not recognize % as a latex comment and thus prints it. How can I get rid of these rows above my table? is there a way for .Rmd files to recognize % as a comment?

+7
r pdf rstudio knitr rnw
source share
1 answer

As @celiomsj said, use the comment argument to print.xtable :

 print(xtable(summary(cars)), comment=F) 
+8
source share

All Articles