Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to produce a sweave document without angle bracket ">" in front of code chunks?

Tags:

r

latex

sweave

How can I produce a Sweave (or pgfSweave) document without angle brackets ">" in front of code chunks? I want people to be able to cut and paste my code directly from the pdf output. Here's a snippet of my document with a code chunk:

Notice that because our incidence matrix consists of 0’s and 1’s, the off-diagonal entries represent the total number of common columns, which is exactly what we wanted. We’ll use the %*% operator to tell R to do this. Let’s first take a look at a small example using toy data of people and groups to which they belong. We’ll coerce the data to an incidence matrix using the table() function, then multiply the incidence matrix by its transpose to get the number of common groups between people.

>\> ToyDat <- data.frame(person = c("Sam", "Sam", "Sam", "Greg", "Tom", "Tom"), group = c("a", "b", "c", "a", "b", "c"), stringsAsFactors = F)
>\> ToyDatM <- as.matrix(table(ToyDat)) 
>\> ToyDatM

But I want the code to look like:

> ToyDat <- data.frame(person = c("Sam", "Sam", "Sam", "Greg", "Tom", "Tom"), group = c("a", "b", "c", "a", "b", "c"), stringsAsFactors = F)    
> ToyDatM <- as.matrix(table(ToyDat)) 
> ToyDatM
like image 889
Solomon Avatar asked May 31 '11 02:05

Solomon


2 Answers

I think options(prompt = " ") at the top of your script will do it.

prompt (in options()) controls the text string used for the prompt in an interactive session and I'm assuming it will do the same for a document processed through Sweave.

EDIT: Thanks to Ben Bolker for pointing out that options(prompt = " ", continue = " ") will also take care of the "+" problem as well.

like image 85
Greg Avatar answered Oct 26 '22 22:10

Greg


Maybe a better strategy is to provide the result of Stangle on your Rnw file -- it'll contain the commands from the entire document, as a script that can be submitted to R or cut-and-paste into an R session.

like image 25
Martin Morgan Avatar answered Oct 27 '22 00:10

Martin Morgan