.md中的xtable,然后在rstudio中以pdf形式显示,显示%注释 [英] xtable in .Rmd then knit as pdf in rstudio shows % comments

查看:115
本文介绍了.md中的xtable,然后在rstudio中以pdf形式显示,显示%注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写R Markdown(.Rmd)文件时使用Rstudio的'knit PDF'选项制作PDF.

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

使用xtable函数创建表时,在pdf中显示使用%在乳胶中注释的文本.使用乳胶和R编织.Rnw文件时,该问题消失了.

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

下面是一个将.Rmd文件编织为PDF以及等效的.Rnw文件进行编织(例如pdf)的示例.

Below the is an example of an .Rmd file to be knitted as PDF and the equivalent .Rnw file, to knitted (as pdf, naturally).

它们的PDF结果相同,除了一行.在表格上方,显示以下内容:

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

xtable 1.7-3软件包在R 3.1.0中生成的%乳胶表%2014年8月6日星期三19:06:37

% latex table generated in R 3.1.0 by xtable 1.7-3 package % Wed 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}

r中xtable(summary(cars))表达式的实际输出如下.您可以看到以%开头的前两行,不同之处在于.Rnw文件隐藏了它们,而.Rmd文件没有隐藏.

The actual output of the xtable(summary(cars)) expression in r is as below. You can see the first two lines, starting with % The difference is that .Rnw file hides them and .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}

我假设问题是编织的.Rmd文件无法将%识别为乳胶注释,因此无法打印. 如何摆脱桌子上方的这些行? .md文件是否有办法将%识别为注释?

I am assuming that the problem is that the knitted .Rmd file doesn't recognise the % as a latex comment and thus prints it. How can I get rid of these lines above my table? is there a way for .Rmd files to recognise the % as comment?

推荐答案

正如@celiomsj所说,在print.xtable中使用comment参数并将其设置为FALSE以忽略参数:

As @celiomsj said, use the comment argument to print.xtable and set it to FALSE to omit the arguments:

print(xtable(summary(cars)), comment=FALSE)

这篇关于.md中的xtable,然后在rstudio中以pdf形式显示,显示%注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆