[R] Sweave, cacheSweave, and data frame

Duncan Murdoch murdoch at stats.uwo.ca
Sun Jul 26 11:11:56 CEST 2009


Shige Song wrote:
> Dear All,
>
> I have been using Sweave (mainly via the Sweave.sh script) and really like
> it. I am working a paper (using Sweave, of course) which includes several
> time-consuming computations, and it gets tedious to re-compile the whoel
> thing every time I made changes. Then I discover the "cacheSweave" package,
> which seems the right solution to my problem. I only have on problem. Here
> is what I did:
>   

I can't help with your question, but another approach to do what you 
want is to have one script that does the time consuming calculations and 
saves the results (using save()) to a file, then have your Sweave 
document load() the object as necessary.  You could then also move the 
read.dta() line to this other script, and load() that data, simplifying 
your Sweave document.

Duncan Murdoch
> ----------------------------------------------
> <<results=hide,echo=false>>=
> library(foreign)
> library(Zelig)
> library(memisc)
> options(digits=4)
> @
>
> <<echo=false>>=
> d <- read.dta("~/project/abortion/data/data_transition_wide.dta")
> @
>
> ...
>
> ----------------------------------------------
>
> It can be compiled using "Sweave.sh foo.Rnw", but when I tried "Sweave.sh -c
> foo.Rnw", I got error message:
>  "...Processing code chunks ...
> 1 : term hide
> Error in data.frame(chunk = options$label, chunkprefix = chunkprefix,  :
>  arguments imply differing number of rows: 0, 1"
>
> I thought it might be an imcompatibiltiy problem between the cacheSweave and
> the foreign packages, but the problem was still there when I tried to read
> the data in using "read.table" function.
>
> Any ideas? Many thanks.
>
> Best,
> Shige
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list