[R] Mysterious R script behavior when called from webserver

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Nov 25 21:36:01 CET 2009


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




More information about the R-help mailing list