Sweave / r - omit leading `>` in code snippets with `echo = true`?

I'm very new to sweave and I feel like this is going to be a tricky question, but I'm struggling to solve it (googling omit ">" Sweave

doesn't work because I can't find the ">"!).

I am including a short script in my document:

<<echo=true, results=hide, eval=false>>=
# This is a simple script.
print('Hello World!\n')


Basically I want the script to render verbatim in the document using any Sweave "code" environment. I don't want to evaluate it - it just shows how a script can be written using functions in the package this document is for.

However, this results in the following in the output:

> # This is a simple script
> print('Hello World!\n')


Is there a way to omit >

? Is this the correct way to set the script to Sweave's doc, or is there another environment designed to be used? (I can use \begin{verbatim}

, but felt like I should use Sweave commands if possible for code snippets.)

I want the result to be

# This is a simple script.
print('Hello World!\n')



source to share

2 answers

You can try changing the parameters prompt

and continue

that define the symbols >

and +


options(continue=" ", prompt=" ")




I love Vincent's first idea of ​​using knitr




Here's a sample of Rnw.


\title{Test case}



<<eval = FALSE, echo = TRUE>>=
# This is a simple script.
print('Hello World!\n')



And then



Convert your .tex file to something pretty and you get

enter image description here



All Articles