The R/Apache Integration Project

This is the old site. Click here for the New Site!

Presented at the Directions in Statistical Computing Conference

DSC2005 paper and presentation.

The Latest Release is 0.1.4

What is it?

R/Apache is a project dedicated to embedding the R interpreter inside the Apache 2.0 (and beyond) web server. It's composed of three parts:

mod_R: the Apache 2.0 module that implements the glue to load the R interpreter.

RApache: the R package that provides the API for programming web applications in R.

libapreq 2.0.4: an Apache sponsored project for parsing request input. If you don't want to compile and install this version, then you can specify which libapreq2 library to use during configuration.


This release has been tested under Debian Linux with Apache 2.0.55, R 2.3.1, and libapreq 2.0.4. Apache2 MUST be compiled with the prefork MPM to compile mod_R. Also, R must have been compiled with the --enable-R-shlib configure flag.


The following is the preferred way to compile and install mod_R:

    $ ./configure --with-apache2-apxs=/path/to/apxs --with-R=/path/to/R
    $ make
    $ make install
Both --with-apache2-apxs and --with-R MUST be specified. Otherwise, trying to figure out the dependencies between the sources and headers and library paths becomes quite complex.

If you don't want to compile and install the bundled libapreq2 version, then add --with-apreq2-config=/path/to/apreq2-config. The version MUST be equal to or greater than 2.0.4.


In order to use mod_R and RApache, you must configure apache to find it. Type help("directives",package="RApache") once mod_R is installed for a little more detail. Add something similar to this to the apache config file:
    LoadModule R_module /path/to/

    <Location /URL>
       SetHandler r-handler
       Rsource /path/to/R/code.R
       RreqHandler function-name
       Rlibrary library-name
Also, MUST be found in the shared library path as it is linked to by mod_R, RApache and the rest of the packages containing shared libraries. You can either set LD_LIBRARY_PATH like this:

$ export LD_LIBRARY_PATH=`/path/to/R RHOME`/lib

or add that path to /etc/ and then run ldconfig.

NOTE: the latest apache2 debian packages cause the web server to run in a very reduced environment, thus one is unable to set LD_LIBRARY_PATH before calling /etc/init.d/apache2. One option is to actually edit that file and add the LD_LIBRARY_PATH explicitly. Another is to use the apache2ctl scripts which are also bundled with the debian packages. Or you can add it to /etc/


All of the documentation is currently in the RApache package. Once you install mod_R, start R and load the RApache package. You'll get a warning that you're currently not running the R interpreter within Apache; just don't try to run any of the code. Sample session:

   > library(RApache)
   Warning message:

   RApache is only useful within the Apache web server.
   It is loaded now for informational purposes only

    in: firstlib(which.lib.loc, package)
   > help(package="RApache")

                   Information on package 'RApache'


   Package:       RApache
   Version:       0.1-1
   Date:          2005-08-02
   Title:         An R interface to the Apache 2.0 web server
   Author:        Jeffrey Horner
   Maintainer:    Jeffrey Horner <>
   License:       Apache License, Version 2.0
   Description:   RApache allows web applications to be written in R and
   executed within the Apache 2.0 web server.
   Built:         R 2.1.0; i386-pc-linux-gnu; 2005-08-02 01:06:26; unix


   IO                      IO in RApache
   apache.add_cookie       Adding Cookies to Outgoing Headers
   apache.add_header       Adding HTTP headers
   apache.allow_methods    RApache Methods
   apache.log_error        Logging Errors to the Apache error log
   Setting the Content Type header
   apr_table               Structure of the apr_table type in RApache
   as.html                 Converting RApache objects to HTML
   directives              RApache directives used in Apace config file
   intro                   Introduction to RApache
   request_rec             Structure of the RApache request record
   return_codes            RApache handler return codes


The R/Apache source code is licensed under the Apache License Version 2.0. Please see the file called LICENSE in the source distribution.


Changes in 0.1.4

    *) Added apache.encode() and apache.decode() for en(de)coding html

    *) R now uses Apache's tmp dir

Changes in 0.1.3

    *) Now plays nicely with mod_cgi (thanks to Jeremy Stephens).
       Apache runs cleanup code per-child after a fork and before
       executing cgi scripts. This was not handled properly, and R/Apache
       caused the child to segfault.

Changes in 0.1.2

    *) Libraries and source files (specified with Rlibrary and Rsource
       in the apache config) are now loaded only once (thanks to Jeremy

    *) Added mod_R version component to Apache response headers

Changes in 0.1.1

    *) Fixed spelling of R_module (thanks to Kevin E. Thorpe) in README
       and RApache/man/directives.Rd.

    *) Fixed compile error on Mac OS X (thanks to Jan de Leeuw).

    *) Fixed bug in as.list.apr_table (thanks to Gregoire Thomas) and
       subsequently in as.list.ra_request_rec

Miscellaneous Files

Topic revision: r23 - 30 Jun 2008, JeffreyHorner

This site is powered by FoswikiCopyright © 2013-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback