The R.rsp package - R Server Pages

by Henrik Bengtsson 2002-2005.

The below part is cut-n-pasted from the help documentation part of the R.rsp package as it was September 2005. For a more up to date version, please see the R.rsp package.

Introduction

R Server Pages, or short RSPs, is an R technology that allows developers to dynamically generate documents of any format, e.g. HTML and LaTeX, but also R code. It allows R code to be embedded into static content.

An RSP is translated into an R servlet, which consists of standard R code, by an RSP translator. When the servlet is evaluated it outputs the final document. This process is illustrated in Figure 1.

translationevaluation
RSP=>R servlet=>final document
(index.rsp)(index.rsp.R)(index.html)
Figure 1. Processing of an RSP document. When processed, an RSP document is first translated to an R servlet of plain R code, which is in turn evaluated and outputs the final document. The filenames within parentesis shows an example where an RSP file is translated into a HTML file.
The reason for using the names "R Server Page" and "R servlet" are their close similarity to "Java Server Page" (JSP) and "Java Servlet" used to dynamically generate HTML pages on web servers [1].

An example of an RSP is:

Counting to ten:<% for (count in 1:10) { %> <%=count%><% } %>. Done!

which when translated becomes an R servlet with R source code:

page <- RspPage(pathname="../inst/rsp/incl/simpleExample.rsp");
out <- getOutput(response);
write(response, "Counting to ten:");
for (count in 1:10) {
write(response, " ");
write(response, count);
}
write(response, ". Done!\n");

(the variable response is an instance of class RspResponse, not needed to be understood in order to write RSP:s). When the R servlet is evaluated, it outputs:

Counting to ten: 1 2 3 4 5 6 7 8 9 10. Done!

Requirements

This is a cross-platform package implemented in plain R. This package depends on the packages R.oo [2] and R.utils packages. Note that no webserver is required to process RSP documents.

Installation

To install this package, please follow the instructions at http://www.braju.com/R/.

References

[1] JavaServer Pages, WikiPedia, 2005.
http://en.wikipedia.org/wiki/JavaServer_Pages
[2] Henrik Bengtsson, The R.oo package - Object-Oriented Programming with References Using Standard R Code, In Kurt Hornik, Friedrich Leisch and Achim Zeileis, editors, Proceedings of the 3rd International Workshop on Distributed Statistical Computing (DSC 2003), March 20-22, Vienna, Austria. http://www.ci.tuwien.ac.at/Conferences/DSC-2003/Proceedings/