看起来像是硬编码到latex.default
(cat("%", deparse(sys.call()), "%\n", file = file, append = file != "", sep = "")
存在于体内,周围没有任何条件)。
我认为你最好的猜测是capture.output
the cat
-d 输出并自行删除注释。
cat(capture.output(latex(head(mtcars), file=''))[-1], sep='\n')
The capture.output
抓住所有的东西latex(...)
cat
s, the [-1]
删除第一行(即“%latex.default”),cat
打印出其他所有内容,并带有换行符分隔符。
您可以定义自己的mylatex
要做到这一点,并且要更聪明一点(例如,不要盲目地剥离输出的第一行,而是只能剥离以“%”开头的行)。
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='')