[R] calling R from python (fwd)
Duncan Temple Lang
duncan at research.bell-labs.com
Mon Dec 23 15:04:02 CET 2002
My immediate guess is that you do not have R compiled as a shared
library, i.e. libR.so. Without this, you cannot use R within Python,
but only Python within R. libR.so is where R_GlobalEnv will come
from.
So check for libR.so in the directory `R RHOME`/bin.
If it is not there, you will have to build R from source
by configuring it with
./configure --enable-R-shlib
Then, re-install the RSPython package and things should work.
There is a shell script in the scripts/ directory of the
installed RSPython package that sets the relevant variables.
Just source that into your shell (i.e. source for csh/tcsh,
or . sciptName for Bash) and that should set the PYTHONLIB
and LD_LIBRARY_PATH correctly.
D.
Agustin Lobo wrote:
> A question for a (experienced) user of the RPython package on
> linux.
>
> I'm trying to call R from python on a linux (Suse 7.3) box.
>
> After installing R CMD INSTALL -c RSPython_0.5-2.tar.gz
>
> I start python and do:
>
> >>> import sys
> >>> sys.path.append('/usr/local/lib/R/library/RSPython')
> >>> sys.path.append('/usr/local/lib/R/library/RSPython/Python')
> >>> sys.path.append('/usr/local/lib/R/library/RSPython/libs')
> >>> sys.path.append('/usr/local/lib/R/library/RSPython/man')
> >>> sys.path.append('/usr/local/lib/R/library/R/RSPython')
> >>> sys.path.append('/usr/local/lib/R/library/RSPython/R/RSPython')
> >>> sys.path.append('/usr/local/lib/R/library/RSPython/R')
> >>> sys.path.append('/usr/local/lib/R/library/RSPython/include')
> >>> sys.path.append('/usr/local/lib/R/include/R_ext')
> >>> import RS
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/lib/R/library/RSPython/Python/RS.py", line 1, in ?
> import RSInternal
> ImportError: /usr/local/lib/R/library/RSPython/libs/RSInternal.so:
> undefined symbol: R_GlobalEnv
> >>> import RS
> >>> RS.call("rnorm", 10);
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> AttributeError: 'RS' module has no attribute 'call'
>
> Any idea of what am I doing wrong? Where should R_GlobalEnv
> be defined?
>
> Thanks
>
> Agus
>
> Dr. Agustin Lobo
> Instituto de Ciencias de la Tierra (CSIC)
> Lluis Sole Sabaris s/n
> 08028 Barcelona SPAIN
> tel 34 93409 5410
> fax 34 93411 0012
> alobo at ija.csic.es
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
--
_______________________________________________________________
Duncan Temple Lang duncan at research.bell-labs.com
Bell Labs, Lucent Technologies office: (908)582-3217
700 Mountain Avenue, Room 2C-259 fax: (908)582-3340
Murray Hill, NJ 07974-2070
http://cm.bell-labs.com/stat/duncan
More information about the R-help
mailing list