[R] Generating R plots via Ruby CGI

Michael Richardson mrich at u.washington.edu
Tue Aug 11 12:18:09 CEST 2009


Greetings,

I'm trying to debug a simple two-line plot routine in R called test.R:

    cor(swiss)
    plot(swiss$Catholic, swiss$Examination)

These commands work fine when typed into R.  They also work fine when  
I invoke this routine by the following line into my terminal:

R --slave < /Library/WebServer/Documents/gsa/test.R

My ultimate goal is to send data to this R routine via a web interface  
mediated by Ruby.  However, I've run into a wall there -- the commands  
that work fine when typed directly into the command line, fail when  
sent via Ruby.

1.  I start with a simple HTML page that calls a simple two-line Ruby  
CGI program (gsa.cgi):

    #!/usr/bin/ruby
    system("R --slave < /Library/WebServer/Documents/gsa/test.R")

2.  However, when I hit the submit button on the HTML page, I get the  
following error messages on my Apache 2 server log:

[Tue Aug 11 01:22:41 2009] [error] [client ::1] Error in function  
(file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"),  :
[Tue Aug 11 01:22:41 2009] [error] [client ::1]   unable to start  
device pdf
[Tue Aug 11 01:22:41 2009] [error] [client ::1] Calls: plot ...  
plot.default -> plot.new -> <Anonymous> -> .External
[Tue Aug 11 01:22:41 2009] [error] [client ::1] In addition: Warning  
message:
[Tue Aug 11 01:22:41 2009] [error] [client ::1] In function (file =  
ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"),  :
[Tue Aug 11 01:22:41 2009] [error] [client ::1]   cannot open 'pdf'  
file argument 'Rplots.pdf'
[Tue Aug 11 01:22:41 2009] [error] [client ::1] Execution halted

3.  If I comment out the line in test.R with the plot command, all  
works fine.

FWIW, I'm running this on a MacBook Pro OS X 10.5.8 with Ruby 1.8.7

Any assistance would be gratefully accepted.

Regards,

Michael L. Richardson, M.D.
University of Washington Radiology




More information about the R-help mailing list