[R] R as server application

kchine at ebi.ac.uk kchine at ebi.ac.uk
Thu Nov 29 21:43:21 CET 2007


Dear Kilian,

The most advanced set of tools and frameworks for using R in Server mode
has been developed as part of the biocep project:
http://www.ebi.ac.uk/microarray-srv/frontendapp/
by using biocep, R can be run as an RMI server exposing a very rich set of
remotly accessible methods.
you can then run the Virtual R Workbench (Universal Gui For R) to connect
and control that server from anywhere.
the README file explain how to install and run the different components
The Virtual R Workbench can be deployed as an applet or via Java Web Start
and the R RMI Server which is normally
accessed via the JRMP protocol can be accessed via HTTP (tunneling) which
means that you can access and control an R Server
sitting anywhere behind any kind of firewall.

The  Virtual R Workbench is the richest existing Gui For R. it works on
all platforms and comes with several advanced views fully connected to R:

- R console view

- R Graphics View : consumes the Graphics primitives produced by the R
Server and renderers them Via Java 2D on real time.
        a popup menu allows to create a snapshot of the R Graphics View,
to save the Graphics as png or jpeg
        the Graphics item in the menu bar (Mouse Tracker option) enable
mouse tracking on the R Graphics (displays axis and the
        real coordinates values of mouse position). you can click on the
Graphics in several mouse positions and retrieve the
        real coordinates values of those positions via the R function
locator() [redefined to work in a virtualized context]

- R File Workspace View : shows the content of your virtual workspace (the
workspace of the R Server) , the file you create appear there
  and can be downloaded to your local disk (popup menu), the scripts you
have on your local disk can be  uploaded to the Remote R instance (popup
menu),
  they appear then in the worksapce view and can be sourced

- The Script Editor View (Tools/script editor) : this is jEdit, the
popular open source editor that has been patched to work as a view within
  the R workbench. it has syntaxe highliting enabled for all programming
languages and some partial syntaxe highlighting for R (activated for
files with .r as extension).
  Two actions has been added (accessible via the Tool bar, and having the
R Symbole in the upper right corner)
  the first toolbar button (run R) allows to upload the content of the
editor to the Remote R Insantce and to source it. you should save before
  the second button (save to R) uploads to the Remote R Instance the
script you are editing (you can see the result in the R Working
Directory View)

- The SpreadSheet View (Tools/ Spreadsheet Editor) : this is JSpreadSheet
(open source project) that has been enhanced, patched and fully connected
to R
  from within the spreadsheet you can :
  + import any R Data (numeric, integer, character, logical, complex,
factor, matrix, data frame ) via the toolbar button import from R
(R+arrow towards the spreadsheet)
  + export selected cells to R and assign the content of the cells to an R
variable via the toolbar button export to R (R+arrow towards R)
    you specify the type of export (numeric, integer, character, logical,
complex, factor, data frame )
    for data frame, you should append to the column name the type of the
column between parathesis ("weight(integer)", "mesure1(numeric)",
"state(factor)", ..)
  + Evaluate an R expression and use the current selection as argument
(the toolbar button R evaluate (R+ruuning man))
    for example you can type "t(%%)" in the R Expression field. This
transposes the selected cells matrix. The result is sent to the
clipboard and you can paste on will
  + type in a cell an expression to evaluate and use any R fucntion,
example in A4 type "=mean(A1:A3)" the content of A4 will be computed
using R fucntion mean and the
    cell value will be the mean of the vector A1:A3. all the R functions
dealing with numeric vectors or matrixes can be used
  + Copy/Paste to and from Excel
  + create as many SpreadSheet Views as needed and specify the suitable
dimensions

- The Help View : can be opened via the menu bar (Help/Help Content) it
allows you to browse the full R help (from the Remote R instance)
  you can also type help(cos) of ?cos in the R console to open this view
and get help about the cos fucntion (for example)
  This a -very light weight- browser. It can be used from simple pages but
shouldn't be confounded with Forefox. trying to acces too complex pages
may freeze the hole
  Workbench. you may want to copy the Url and paste it to your browser url
field.

- The Inspector View : allows to browse the internal structure of R
Objects. This is enabled for all standard R Objects and for all the S4 R
Objects for which a mapping has been
  generated

- The console log viewer : allows to see the output of R on real time.
this is usefull when an action (installing a package,..) takes time. The
console doesn't display
  log before the evalutation is fully done.

- The docking Framework :  allows you to compose your views on will,
drag&drop them, dock/undock them, expand them, reduce them ....

You can run the virtual R Workbench to control a local R Process as well.
to have an idea about this tool, you can just use the following URL :
http://www.ebi.ac.uk/microarray-srv/frontendapp/rworkbench.jnlp
or type 'javaws
http://www.ebi.ac.uk/microarray-srv/frontendapp/rworkbench.jnlp'
this installs the workbench on your machine (Mac OS X and Windows), the
installed R is automatically detected and used. On windwos,
an embedded R can be deployed if you don't have an R installed.

Besides controlling an R Server, you can deploy an infrastructure for
providing an R Server on demand (without process creation overhead).
the R servers can be created on an hetergenous parc of machines or on an
LSF cluster. They are managed as a pool of resources that
can be supervised and several tools and frameworks take care of their life
cycle mangement.

by deploying such an infrastructure, you can -form within R- create a set
of R servers and use them from your R console to parallelize your
computational tasks
in the snow package fashion (the rmi snow features are only a prototype
and are not as robust and finalized as the rest of the tools)

by deploying such an infrastructure you can also provide on the fly
generation of R Graphics (HTTP R Graphics Server) :
example :
http://127.0.0.1:8080/frontendapp/graphics?height=500&width=400&expression=hist(rnorm(100))
once you deployed biocep, this URL returns a JPG generated on the fly by a
servlet that borrows an R Server, evaluates the expression,
consumes the graphical primitives from the R Server, creates a bufferized
Image using Java 2D and returns it to the browser.
you will be surprized by the speed of the generation.

another use case is to control your R Server via a statefull webservice.
this is shown in demo5

by using biocep programatically, you have access to even more powerfull
functions. The R Servers remote methods are fully object oriented.
all R standard types are mapped. a mapping can be generated for any S4
objects and calls to the R Server from a Java Client can get as close to R
functions calls as this :

//java code :
 RChar s = (RChar) r.call("paste", new RChar("str1"), new RChar("str2"),
new RNamedArgument("sep", new RChar( "--")));
 ExpressionSet kidney =
(ExpressionSet)r.evalAndGetObjectAsReference("kidney");
 Vsn fit = (Vsn) r.call("vsn2", kidney);
 ExpressionSet normalizedKidney = (ExpressionSet)
 r.call("predict", fit, new RNamedArgument("newdata", kidney));

The Java Wrappers of R objects can be 'light weight' means just proxies
referencing an object and the arguments of r.call can
be R objects proxies from different R Servers (Distributed Data). an S4
Java object can be a proxy composed with fields that are
them selves proxies to objects sitting on different R Servers.

I hope it will help.

Cheers,

Karim



> I found this link:
>
> http://jesus-loves-grass.blogspot.com/search/label/R%20server
>
> Which points to RSOAP and Rserver.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list