问题描述
我在 rmarkdown 文件中使用 Hmisc.当我创建一个表时,这就是我所做的
Im using Hmisc in rmarkdown file. when I create a table this is what I do
---
output: pdf_document
---
```{r Arrests Stats, results ='asis', message = FALSE, warning = FALSE, echo = FALSE}
# render the table
options(digits=1)
library(Hmisc)
latex(head(mtcars), file="")
```
latex 输出的第一行如下所示
The latex output has the first row showing as below
%latex.default(cstats, title= title....
egin{table}...
.
.
.
end{tabular}
注意 '%' 我需要找出删除第一行,因为它在编织时显示在 PDF 文档上
Notice the '%' I need to figure out to remove the first line as it shows on the PDF document when its weaved
推荐答案
看起来这是硬编码到 latex.default
(cat("%", deparse(sys.call()), "%", file = file, append = file != "", sep = "")
在正文中,周围没有条件).
Looks like that's hard-coded into latex.default
(cat("%", deparse(sys.call()), "%", file = file, append = file != "", sep = "")
is in the body, with no conditional surrounding it).
我认为您最好的猜测是 capture.output
cat
-d 输出并自己删除评论.
I think your best guess then would be to capture.output
the cat
-d output and strip the comment yourself.
cat(capture.output(latex(head(mtcars), file=''))[-1], sep='
')
capture.output
捕获 latex(...)
cat
的所有内容,[-1]
删除第一行(作为 '%latex.default'),cat
打印出其他所有内容,并带有换行符.
The capture.output
catches all the stuff that latex(...)
cat
s, the [-1]
removes the first line (being the '%latex.default'), the cat
prints out everything else, with newline separator.
您可以定义自己的 mylatex
来执行此操作,并且更聪明一点(例如,不要盲目地剥离输出的第一行,您只能在它以 '% 开头时才剥离它').
You might define your own mylatex
to do this, and be a little more clever (e.g. instead of blindly stripping the first line of the output, you could only strip it if it started with '%').
mylatex <- function (...) {
o <- capture.output(latex(...))
# this will strip /all/ line-only comments; or if you're only
# interested in stripping the first such comment you could
# adjust accordingly
o <- grep('^%', o, inv=T, value=T)
cat(o, sep='
')
}
mylatex(head(mtcars), file='')
这篇关于Hmisc乳胶功能需要删除第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!