[R] running R from PHP

Philippe Glaziou glaziou at pasteur-kh.org
Tue Feb 3 06:24:33 CET 2004


@biology.nmsu.edu <brook at biology.nmsu.edu> wrote:
> I would like to construct a PHP script that runs R to generate a
> graphics file.  Running R itself is no problem.  However, it seems
> impossible to instantiate one of the graphics devices to create
> output.  For example, the "normal" bitmap devices (e.g., jpeg, png,
> etc.) are derived from X11, which requires a display.  This seems
> true, even if no output is ever directed to a real display.  For some
> reason, the postscript device seems to suffer from similar problems.
> 
> Is there a trick to creating a graphics device in the absence of an
> actual display in order to create an image in a file?


If you need a bitmap graphic file, I would suggest the use of
ImageMagick:


cunegonde:~/tmp> ls
foo

cunegonde:~/tmp> cat foo
pdf(file="g.pdf")
plot(1:5)
dev.off()

cunegonde:~/tmp> R --no-save <foo>/dev/null && convert g.pdf g.png

cunegonde:~/tmp> ls -g
-rw-------    1 glaziou      3374 2004-02-03 11:58 g.pdf
-rw-------    1 glaziou      4115 2004-02-03 11:58 g.png
-rw-------    1 glaziou        80 2004-02-03 11:58 foo


This works from a unix console without X running (the postcript
device works similarly on my machine). R can easily be fed this
way with a file and parameters passed from a php script.

-- 
Philippe Glaziou, MD
Epidemiologist
Institut Pasteur du Cambodge




More information about the R-help mailing list