r - knitr 不会在 R 3.0.2 上转换 xtable 输出

标签 r knitr xtable

我想使用 xtable() 创建一个 tex 表.这是我在 Win 7 上使用相同 R 版本时的最小示例。

\documentclass[a4paper,12pt,twoside]{article}

\begin{document}

<<load-packages,include=TRUE,echo=TRUE>>=
library(xtable)
@

<<testing-xtable,echo=TRUE,cache=FALSE,include=TRUE>>=
tab <- matrix(1:50,nrow=10)
rownames(tab) <- letters[1:10]

print(
  xtable(
    x=tab,
    caption="A table",
    label="tab",
    align=rep("c",times=6),
    digits=3,
    display=rep("f",times=6)
    ), 
  sanitize.colnames.function=identity,
  include.rownames=FALSE,
  table.placement="h"
  )
@
\end{document}

我得到的不是一张漂亮的表,而是 xlatex() 的逐字代码输出在pdf文档中。

这是knitr的输出:
> grDevices::pdf.options(useDingbats = FALSE); require(knitr); opts_knit$set(concordance     = TRUE); knit('xtable.Rnw', encoding='UTF-8')
Loading required package: knitr


processing file: xtable.Rnw
  |.............                                                    |  20%
  ordinary text without R code

  |..........................                                       |  40%
label: load-packages (with options) 
List of 2
 $ include: logi TRUE
 $ echo   : logi TRUE

  |.......................................                          |  60%
  ordinary text without R code

  |....................................................             |  80%
label: testing-xtable (with options) 
List of 3
 $ echo   : logi TRUE
 $ cache  : logi FALSE
 $ include: logi TRUE

  |.................................................................| 100%
  ordinary text without R code


output file: xtable.tex

[1] "xtable.tex"
> 
> 
Running pdflatex on xtable.tex...completed

Created PDF:             ~/Dropbox/intern/sandbox(coding)/tex/chapter/chapter/sandbox/xtable/xtable.pdf

Issues: 2 badboxes

代码块 testing-xtable应该在最终文件中得到回应,但事实并非如此。 This is the pdf output.我怀疑 Ordinary text without R code 的消息.这是正常的吗?

任何帮助将不胜感激。

最佳答案

使用 chunk option results='asis' .

关于r - knitr 不会在 R 3.0.2 上转换 xtable 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21482722/

相关文章:

r - 绘制指数函数返回多余的线

R:在谷歌搜索一个字符串并返回点击数

r - R tm 文本挖掘中的自冲突停用词

python - rmarkdown python代码块模块matplotlib没有属性pyplot

r - 禁用绘图缓存

r - 使用 xtable 函数更改从 lm 回归中获得的表的行名称

r - xtable 标题对齐与表格左对齐或居中(使用 knitr)

R:Shiny - 无功输出在 grid.arrange(from gridExtra) 中不起作用

r - Blogdown 和 hugo 不解析 Markdown 中的 html 标签

r - xTable、Sweave、R、交叉表中的计数和百分比