问题描述
我在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="")
```
乳胶输出的第一行显示如下
The latex output has the first row showing as below
%latex.default(cstats, title= title....
\begin{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()), "%\n", file = file, append = file != "", sep = "")
在主体中,没有任何条件包围).
Looks like that's hard-coded into latex.default
(cat("%", deparse(sys.call()), "%\n", 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='\n')
capture.output
捕获latex(...)
cat
s的所有内容,[-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='\n')
}
mylatex(head(mtcars), file='')
这篇关于Hmisc乳胶功能需要去除第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!