Sweave + RweaveHTML: cat output does not appear in the output

杀马特。学长 韩版系。学妹 提交于 2020-02-04 04:59:12

问题


I have a problem with Sweave + RweaveHTML

I want the output of cat ends to up in the html file being generated. I have a case in which it does not and I can't figure out why :(

test = function()
{
   #bla bla;
   cat("Result is...")
}

And then in the Rnw file I tried all of these:

<<echo=FALSE, results=html, include=TRUE>>=
test()
@

<<results=html, include=TRUE>>=
test()
@

<<results=html>>=
test()
@

<<>>=
test()
@

But I don't get the cat output in the resulting HTML file. I'm pretty sure this is supposed to work...

Any ideas of what I'm supposed to do to get the stdout ouput to the final html file?

Thx!


回答1:


The RweaveHTML driver works differently than the RweaveLatex driver in that to create output, the result from every line of code is processed with the generic function HTML. Other ways of creating output don't work. So to get output from within a function, there are two ways I know of; one is to return a value to be processed by the HTML generic, and the other is to call HTML directly. The following replacement of your test function demonstrates both.

test <- function() {
   #bla bla;
   HTML("Result is...")
   "Return value is"
}

It's also possible to replace cat with HTML; then your original function would work. But it's a bit of a hack and could have unforeseen consequences; you'd put

cat <- HTML

in a (probably hidden) Sweave chunk at the beginning of the document.



来源:https://stackoverflow.com/questions/6889862/sweave-rweavehtml-cat-output-does-not-appear-in-the-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!