[R] Sweave, cacheSweave, and data frame

Andreas Borg borg at imbei.uni-mainz.de
Mon Dec 7 13:05:24 CET 2009


It's been a while since this thread appeared, but I had the same problem 
and don't want to keep the solution for myself.

A small, reproducible example:

<<cache=true>>=
a=1
@

<<>>=
a+1
@

Compiling with cacheSweave gives an error:

 > library(cacheSweave)
Lade nötiges Paket: filehash
filehash: Simple key-value database (2.0-1 2008-12-19)
Lade nötiges Paket: stashR
A Set of Tools for Administering SHared Repositories (0.3-3 2009-03-26)
 > Sweave("cacheSweaveExample.rnw", driver=cacheSweaveDriver)
Writing to file cacheSweaveExample.tex
Processing code chunks ...
 1 : echo term verbatim
Fehler in data.frame(chunk = options$label, chunkprefix = chunkprefix,  :
  arguments imply differing number of rows: 0, 1

The solution is to use named code chunks as in this corrected example:

<<a, cache=true>>=
a=1
@

<<b>>=
a+1
@

The problem is that the cacheSweave driver tries to store the label of a 
code chunk, along with other information, in a data frame. If there is 
no label, the corresponding variable is NULL which gives an error.

I don't know if this is a bug or intended. I think it is more safe this 
way than to rely on some automatic labelling. Anyway, there should be a 
note in the documentation.


> Shige Song
> Sat, 25 Jul 2009 20:07:47 -0700
>
> 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:
>
> ----------------------------------------------
> <<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
>   

-- 
Andreas Borg
Medizinische Informatik

UNIVERSITÄTSMEDIZIN
der Johannes Gutenberg-Universität
Institut für Medizinische Biometrie, Epidemiologie und Informatik
Obere Zahlbacher Straße 69, 55131 Mainz
www.imbei.uni-mainz.de

Telefon +49 (0) 6131 175062
E-Mail: borg at imbei.uni-mainz.de

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der
richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den
Absender und löschen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe
dieser Mail und der darin enthaltenen Informationen ist nicht gestattet.




More information about the R-help mailing list