# 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')



+3

source to share

You can try changing the parameters prompt

and continue

that define the symbols >

and +

.

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



+7

source

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

.

install.packages("knitr")
library(knitr)




Here's a sample of Rnw.

\documentclass[a4paper]{article}
%\usepackage{Sweave}

\title{Test case}
\author{romunov}

\begin{document}

\maketitle

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

\end{document}




And then

knit("coffee.Rnw")




Convert your .tex file to something pretty and you get

+6

source

All Articles