[R-sig-Geo] Problem with Sweave and spplot

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Sep 2 09:26:34 CEST 2009


On Wed, Sep 2, 2009 at 7:50 AM, Edzer
Pebesma<edzer.pebesma at uni-muenster.de> wrote:
> I think this is a well-known issue, and a FAQ:
> http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f
>
> Manual processing is not needed.
>
> I agree that the resulting code with print(spplot(...)) looks ugly; in
> the ASDAR book we basically tricked things by having two code sections,
> one that is printed but not evaluated, and one that is evaluated but not
> printed. Not really nice but ... it worked.
> --

 I haven't tried this in an Sweave doc yet, but wouldn't it be neater
to redefine spplot(...) to call print(spplot(...))?

This works interactively:

 > library(sp)
 > spplot.orig=spplot
 > spplot=function(...){print(spplot.orig(...))}

such that

 > z = spplot(meuse) # shows the plot
 > z = spplot.orig(meuse) # doesn't show the plot

If you put the definition in a hidden section in your Sweave code,
then you might be able to just have plain spplot() function calls and
hence only one code section. I *hate* it when I'm writing Sweave docs
and think I need a hidden, executed code block and a visible,
unexecuted and slightly different code block - it seems like a massive
fail in the whole Sweave concept...

Barry



More information about the R-sig-Geo mailing list