开发者

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

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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜