更新时间:2023-12-04 11:56:40
看起来这是硬编码到 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='')