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() fu开发者_Go百科nction, 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
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.
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.
精彩评论