我想使用 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/