问题
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