The S-Python Interface FAQ

  • When I try to load the RSPython library into R I get an error about pthread_sigmask, e.g.
          
    Error in dyn.load(x, as.logical(local), as.logical(now)) : 
    	unable to load shared library "/tmp/R/pkg/RSPython/libs/RSPython.so":
      /tmp/R/pkg/RSPython/libs/RSPython.so: undefined symbol: pthread_sigmask
    Error in library(RSPython) : .First.lib failed
    
    This means that your version of Python has been compiled with the pthreads library and so to must the RSPython package. To enable this, use the --with-threads argument to configure when installing RSPython. Typically, this is done as
     R CMD INSTALL -c --configure-args='--with-threads' RSPython
    
  • When I load the RSPython library into R, I get an error about a missing symbol openpty, e.g.
    > library(RSPython)
    Error in dyn.load(x, as.logical(local), as.logical(now)) : 
    	unable to load shared library "/tmp/R/pkg/RSPython/libs/RSPython.so":
      /tmp/R/pkg/RSPython/libs/RSPython.so: undefined symbol: openpty
    Error in library(RSPython) : .First.lib failed      
    
    This means that the RSPython library needs to be linked against libutil.so, usually in /usr/lib. Until the configuration for the package is fixed to take care of this automatically, add -lutil to the end of the PKG_LIBS variable setting in src/Makevars.in and re-install the package.
  • When I import the RS module, I get an error about a symbol R_GlobalEnv.
    Well, the probable answer is that R is trying to load the library R_X11.so and that is failing. (It attempts to find symbols in R, but the way that R is loaded into Python means it cannot find them! It is a dynamic loading issue.)
    The way around this is to return to the R installation and link R_X11.so against libR.so. Currently, the simplest thing to do is edit the file src/unix/X11/Makefile and specifically the $(SHLIB) rule. All you need to do is add -L$(R_HOME)/bin -lR in the link command. So, it should look like
    $(SHLIB): $(OBJECTS)
            $(SHLIB_LD) $(SHLIB_LDFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) -L$(R_HOME)/bin -lR $(ALL_LIBS)
    
    Then invoking make in that directory should create the R_X11 shared library (R_X11.so many systems) in $R_HOME/bin.
    We might find a convenient way to specify this during the R installation procedure.
  • When I issue the
    import RS
    command to load R, I get the error
    >>> import RS;
    Traceback (innermost last):
       File "", line 1, in ?
    ImportError: libR.so: cannot open shared object file: No such file or directory      
    
    This means that you haven't got the value of the LD_LIBRARY_PATH environment variable set correctly when you run python. You can do this with
     setenv LD_LIBRARY_PATH $R_HOME/bin       #csh and tcsh
     export LD_LIBRARY_PATH=$R_HOME/bin       # bash
    
    and the run python.

    Note that you cannot set the value of LD_LIBRARY_PATH from within python and have it take effect. That is

    % python
    >>> from os import environ
    >>> environ['LD_LIBRARY_PATH'] = environ['R_HOME']+ "/bin"
    >>> import RS
    
    will not work.
    This is because the facility that does dynamic loading reads the value of LD_LIBRARY_PATH very early in the initialization of any application. And it never reads it again.
  • How do I get graphics displays (e.g. the X11 device) to appear?
    If you have R_X11.so compiled as in the question above (i.e. linking against libR.so), it should be as simple as
           RS.call("plot", [1,2,3])
    
  • When I attempt to call R from within a Python session or script, the call
        import RS
    
    gives an error message
    ImportError: No module named RS
    
    The problem is that you have not set the value of the environment variable PYTHONPATH correctly. This variable must include the fully qualified directories Python/ and libs/ of the directory into which the R package was installed.

    Also, take a look at the return value from

    import sys      
    sys.path
    
    The latest version now tries to set this automatically for you. See .PythonPath().

  • Last modified: Thu Nov 22 08:21:26 EST 2001