he following session assumes that the installation procedure (see following
sections) was already completed. In particular, R loads pyServer file on
startup and python finds the r_com module.
Always start pyServer from R shell before calling into any r_com functionality
from Python shell!!! To start pyServer, type the command pyServer.run() into R
While the pyServer is running it is possible to call into that R shell from
The "do" function executes an R statement in the R shell. The "get" function
retrieves contents of an R variable into the Python namespace. The function
"set" puts data from Python shell into R shell (an example follows shortly).
Python directive of the form r.anyRFunction(anyArguments) marshals the
anyRArguments into R namespace, executes anyRFunction in the R namespace and
marshals the result back into the Python namespace. For example, the sequence
displays the "R Graphics" window:
The meaning of axis annotations will be clear in the following sections. The
recipe for getting rid of it follows immediately.
It is possible to use arguments that are already inside the R namespace. For
example, the sequence of commands
displays the following window:
The RPy users may be delighted to know that the "R Graphics" window is
responsive, the way it would be if called directly from R shell.
There is no blocking of Python shell while the "R Graphics" window is
displayed because the "plot" command of the R shell does not block. This is an
improvement over matplotlib and pylab.
The command r.stop() releases the R shell (the pyServer.run() directive exits)
and prevents further communication until the command "pyServer.run()" is
executed again in the R shell. For example,
At this point the "pyServer.run()" returns in the R shell
and the R namespace may be explored directly:
To resume comunication execute "pyServer.run()" again:
and continue manipulating the same R namespace from Python shell: