nathaneastwood
nathaneastwood

Reputation: 3764

How do I send output to the console instead of a document when knitting

I want to be able to send information to the R console for a user to see when I am knitting a document. So for example, I have a code chunk:

<<descriptive, child = 'descriptive.Rnw'>>=
@

But before this, I would like to return the line "Beginning the descriptive section..." to the console. So my question is, how do I send a code chunk to the R console instead of the LaTeX document?

Thanks in advance

Upvotes: 2

Views: 151

Answers (1)

Spacedman
Spacedman

Reputation: 94202

On a unix system, hide a chunk of code that calls system to echo a message:

<<fnord,results="hide",echo=FALSE>>=
system("echo '\\n****** hello world *******\\n'")
@ 
<<runme>>=
x=1:10
y=runif(10)
plot(x,y)
@ 

The first chunk spits out a message to the console, the second runs normally. Note use of a single quoted string to stop shell expansion of the stars, and the escaped \n to make a newline. The show and echo options stop the chunk appearing in the output.

Upvotes: 3

Related Questions