[R] Mysterious R script behavior when called from webserver

Dylan Beaudette debeaudette at ucdavis.edu
Wed Nov 25 21:41:57 CET 2009


On Wednesday 25 November 2009, Barry Rowlingson wrote:
> On Wed, Nov 25, 2009 at 8:15 PM, Dylan Beaudette
>
> <debeaudette at ucdavis.edu> wrote:
> > Hi,
> >
> > I am trying to transition a system based on dynamic image generation (via
> > R) from our development system to a production environment. Our R script
> > functions as expected when run by a regular user. However the script dies
> > when calling the png() function, when started by the webserver user.
> >
> > Here are some details
> >
> >>sessionInfo()
> >
> > R version 2.9.2 (2009-08-24)
> > i686-pc-linux-gnu
> > locale:
> > C
> > attached base packages:
> > [1] stats     graphics  grDevices utils     datasets  methods   base
> >
> > The script gets to this line:
> >
> > png(file=filename, width=600, height=400)
> >
> > and then dies. It leaves an empty PNG file where it should be, however it
> > never finishes the file. If
> >
> > I replace png() with pdf() an output file is generated and closed by
> > dev.off() as expected.
> >
> > It seems like the environment is setup just as when started by a regular
> > user, specifically the LD_LIBRARY_PATH variable.
> >
> > This behavior suggests that R is encountering an error, and stopping.
> > However there is no reporting of the error. Is there any way to get more
> > verbose error reporting?
>
>  How is R run from your web server? Does it start a new R process or
> is it an apache module thing with a dynamically linked R (if such a
> thing even exists)? Can't figure out how you could get more error
> reporting without knowing that - you need to see where stderr is
> going, possibly to the apache error.log file - have you looked there?
>
>  Have you tried a trivial png generating example, just a three liner:
>
> png(file="/tmp/wherever/foo.png")
> plot(1:10)
> dev.off()
>
>  just in case it's something else previous in your script that's
> breaking things.
>
>  In the old days of R you needed an X11 display connection to do PNG
> graphics, but that was fixed before 2.9, I think. Try it interactively
> but unset the DISPLAY variable first:
>
>  export -n DISPLAY
>  R
>
>   > png(... etc etc)
>
>  Does that work?
>
> Barry

Hi Barry thanks for the tips. I was able to get more error reporting by 
placing the png() function inside of try(). Turns out this was an X11 related 
problem-- probably an unset DISPLAY variable for the www user. 

For the record, R was being run by PHP. I just realized that R was not 
compiled with Cairo support-- fixing this should make the problems go away...

Cheers,
Dylan



-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341




More information about the R-help mailing list