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

时间:2014-01-31 14:41:49

标签: 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}

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

这是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持怀疑态度。这是正常的吗?

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:7)

使用chunk option results='asis'