Skip to content

Problem with Sweave and spplot

8 messages · Matthieu Stigler, Virgilio Gomez Rubio, Els Ducheyne +3 more

#
Hi

I'm facing problems using Sweave with spplot... there is no error
message but the pdf produced has errors and then latex compilation
fails... I really don't know where that come from, did anyone
experience something similar?

I've put the file on the net:
-the Sweave file:
http://s000.tinyupload.com/download.php?file_id=06883775011103568715&t=0688377501110356871533520
-the map data: http://s000.tinyupload.com/download.php?file_id=77859174637181270102&t=7785917463718127010263143

So after downloading oe should just run:
R
Sweave("WorkingPaper2.Rnw.txt")

Would you be so nice to test it and tell further:
-Do you have errors?
-Is Sweave running but not providing pdf not working?

Thanks a lot

Matthieu Stigler
#
Hi,
Have you embedded the spplot() function inside a print() function.
Lattice graphics need to be printed() inside Sweave. Something like:

print(spplot(mymap, "mydata"))

Otherwise I believe that you will get some PDF files but they will be
empty or borken.

Best wishes,

Virgilio
#
Dear all
I faced the same problem, spplot does not create the output that  
sweave will integrate
I solved this by manually saving the spplot outputs and then hard code  
it in the tex file,  but clearly there should be a better way

Els
On 1 Sep 2009, at 17:01, Matthieu Stigler 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.
--
Edzer
Els Ducheyne wrote:

  
    
#
yes, the print(spplot()) did solve the problem!

thanks!

2009/9/2 Edzer Pebesma <edzer.pebesma at uni-muenster.de>:
#
On Wed, Sep 2, 2009 at 7:50 AM, Edzer
Pebesma<edzer.pebesma at uni-muenster.de> wrote:
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
#
Hi,

Could this be an issue with the way in which lattice graphics behave 
when 'sourced' from a script file? If so, then something like this may help:

p <- spplot(...)
print(p)

Cheers,
Dylan
On Tuesday 01 September 2009, Els Ducheyne wrote:

  
    
#
On Wed, Sep 2, 2009 at 8:26 AM, Barry
Rowlingson<b.rowlingson at lancaster.ac.uk> wrote:

            
Well, I have now tested it in an Sweave doc, and this works and lets
you do plain spplot(...) in code sections. Whether there's any other
side effects I don't know... Here you go:

<<echo=FALSE, results=hide>>=
library(sp)
spplot.orig = spplot
spplot = function(...){print(spplot.orig(...))}
@

<<fig=TRUE>>=>
data(meuse)
coordinates(meuse)=cbind(meuse$x,meuse$y)
spplot(meuse,"dist")
@