【发布时间】:2014-02-24 07:18:10
【问题描述】:
我想使用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 的消息持怀疑态度。这正常吗?
任何帮助将不胜感激。
【问题讨论】:
-
奇怪。你可以尝试在你的第一个代码块的选项中写
cache=FALSE吗?什么是 nhtm.results.tab? -
你在你的 Ubuntu 机器上安装了
xtable包吗?require不会像library那样对丢失的包抛出错误。 -
哦,我的错。我做了
chache=FALSE并将nhtm.results.tab更改为tab。之后,我修复了另外两条错误消息,突然错误消息消失了。但是,现在输出是xtable()的逐字输出,即使echo=FALSE也是如此。现在更奇怪的是,我使用此代码的原始文档现在可以完美运行,而且我没有更改任何代码块 o.O @BrandonBertelsen -
@James 是的,它已安装并且是最新的。
-
听起来“某事”正在被缓存并导致一些奇怪的行为。