Skip to main content Skip to navigation

David Firth, software: CGIwithR

CGIwithR has moved!

Duncan Temple Lang at UC Davis has kindly taken over the maintenance and development of CGIwithR, and has made various useful improvements. For up-to-date information see

The information below relates to versions 0.70 and earlier. It was last updated at 2005-05-10.


CGIwithR is a package for R, which allows R to be used as a CGI scripting language. Possible applications include the provision of online special-purpose calculators (such as the QV Calculator), using R as the computational "back end"; and the processing of web forms more generally, using R as an alternative to a more standard scripting language such as Perl.

Find an extended overview (PDF, 600k) here.

For the time being, at least, CGIwithR works only on Unix-like systems with a Bourne shell or equivalent. This includes certain Windows setups (see below for details).

The package sources, and windows binary, are available at CRAN sites for installation into R in the standard way. An extended user manual is provided in addition to the usual R help files.

The CGIwithR software is made available free, under GPL version 2. It comes with ABSOLUTELY NO WARRANTY.


1. Can CGIwithR be used with a web server running under Microsoft Windows? The short answer is no. The longer answer is probably yes, provided that the web server supports CGI, and that standard unix tools (including bash) are installed, e.g., from Probably some tweaking of the R.cgi shell script will also be needed.
News March 2004: Adam Lyon kindly emailed me to say he has succeeded in getting CGIwithR to work under Windows. The details are in file windows.txt.
News Oct 2004: File windows.txt is updated to include some further helpful advice from Kurt Sys.
News Sep 2005: File windows.txt is updated to include yet more helpful advice from Carlos Rendon.

2. When trying to use CGIwithR, for example with the trivial.R example, I get no response from the webserver and this error message in the httpd log file:

    Premature end of script headers: /usr/var/cgi-bin/R.cgi

Why? Almost certainly this is because one or more of R.cgi, .Rprofile and trivial.R has been put in the wrong place on your system.

3. I have recently updated R and now my CGIwithR scripts don't work any more. I have checked that my installed CGIwithR package is the latest version. Any clues? Did you perhaps forget to install the new R.cgi file? This comes inside the inst subdirectory of the CGIwithR package, and it needs to be installed in your "cgi-bin" (or whatever it's called on your system) directory.

Version history

0.70: in R.cgi, removed the argument --gui=none for compatibility with R 2.1.0 (2005-05-10)
0.65: fixed bugs in indentPrint() and scanText() (2004-10-10)
0.63: minor cosmetic corrections to documentation files (2004-09-20)
0.61: provided an index.html file for the installed overview document (2004-01-21)
0.60: fixed a bug in the tag() and img() functions (2004-01-12)
0.2: first release on CRAN (2002-10-28)

Related links: