Skip to content

[Rcpp-devel] Rcpp and rpy2

6 messages · Jonas Rauch, Dirk Eddelbuettel

#
Is Rcpp compatible with rpy2?
I would like to call a very complex R function from python. My function
depends on code implemented with Rcpp. When I try to load Rcpp from python
via

import rpy2.robjects as robjects
robjects.r('library(Rcpp)')

I get the following:

Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object
'/home/jonas/R/x86_64-unknown-linux-gnu-library/2.13/Rcpp/libs/Rcpp.so':
  /home/jonas/R/x86_64-unknown-linux-gnu-library/2.13/Rcpp/libs/Rcpp.so:
undefined symbol: R_ClassSymbol
Error: package/namespace load failed for 'Rcpp'
Traceback (most recent call last):
  File "RcppTest.py", line 2, in <module>
    robjects.r('library(Rcpp)')
  File
"/usr/local/lib/python2.7/dist-packages/rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/__init__.py",
line 225, in __call__
    res = self.eval(p)
  File
"/usr/local/lib/python2.7/dist-packages/rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/functions.py",
line 82, in __call__
    return super(SignatureTranslatedFunction, self).__call__(*args,
**kwargs)
  File
"/usr/local/lib/python2.7/dist-packages/rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/functions.py",
line 34, in __call__
    res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error: package/namespace load failed for
'Rcpp'
#
Hi Dirk and Romain,

Aparrently libR is not loaded by rpy2, at least not in a way such that Rcpp
can access it. I have solved the problem by adding -lR to the linker flags
when building Rcpp. Since for normal use of Rcpp from R this does not make a
difference, would you mind adding this to the Makevars file in a future
version of Rcpp? Or does this lead to problems in case R is build without
libR.so?

Best regards,
Jonas

---------- Forwarded message ----------
From: Jonas Rauch <jonas.rauch at googlemail.com>
Date: Fri, Aug 12, 2011 at 10:36 AM
Subject: Rcpp and rpy2
To: rcpp-devel <rcpp-devel at r-forge.wu-wien.ac.at>


Is Rcpp compatible with rpy2?
I would like to call a very complex R function from python. My function
depends on code implemented with Rcpp. When I try to load Rcpp from python
via

import rpy2.robjects as robjects
robjects.r('library(Rcpp)')

I get the following:

Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object
'/home/jonas/R/x86_64-unknown-linux-gnu-library/2.13/Rcpp/libs/Rcpp.so':
  /home/jonas/R/x86_64-unknown-linux-gnu-library/2.13/Rcpp/libs/Rcpp.so:
undefined symbol: R_ClassSymbol
Error: package/namespace load failed for 'Rcpp'
Traceback (most recent call last):
  File "RcppTest.py", line 2, in <module>
    robjects.r('library(Rcpp)')
  File
"/usr/local/lib/python2.7/dist-packages/rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/__init__.py",
line 225, in __call__
    res = self.eval(p)
  File
"/usr/local/lib/python2.7/dist-packages/rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/functions.py",
line 82, in __call__
    return super(SignatureTranslatedFunction, self).__call__(*args,
**kwargs)
  File
"/usr/local/lib/python2.7/dist-packages/rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/functions.py",
line 34, in __call__
    res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error: package/namespace load failed for
'Rcpp'
#
On 12 August 2011 at 14:33, Jonas Rauch wrote:
| Hi Dirk and Romain,
| 
| Aparrently libR is not loaded by rpy2, at least not in a way such that Rcpp can
| access it. I have solved the problem by adding -lR to the linker flags when
| building Rcpp. Since for normal use of Rcpp from R this does not make a
| difference, would you mind adding this to the Makevars file in a future version
| of Rcpp? Or does this lead to problems in case R is build without libR.so?

I would be somewhat hesitant to do so as it may affect all users of Rcpp.

Rcpp is for getting code into R, and we can take libR as given as R is always
around when loading Rcpp.  I think the problem is really with the linker and
passing symbols through from one end to the other.

Other views, anyone?

Dirk


| Best regards,
| Jonas
| 
| ---------- Forwarded message ----------
| From: Jonas Rauch <jonas.rauch at googlemail.com>
| Date: Fri, Aug 12, 2011 at 10:36 AM
| Subject: Rcpp and rpy2
| To: rcpp-devel <rcpp-devel at r-forge.wu-wien.ac.at>
| 
| 
| Is Rcpp compatible with rpy2?
| I would like to call a very complex R function from python. My function depends
| on code implemented with Rcpp. When I try to load Rcpp from python via
| 
| import rpy2.robjects as robjects
| robjects.r('library(Rcpp)')
| 
| I get the following:
| 
| Error in dyn.load(file, DLLpath = DLLpath, ...) :
| ? unable to load shared object '/home/jonas/R/x86_64-unknown-linux-gnu-library
| /2.13/Rcpp/libs/Rcpp.so':
| ? /home/jonas/R/x86_64-unknown-linux-gnu-library/2.13/Rcpp/libs/Rcpp.so:
| undefined symbol: R_ClassSymbol
| Error: package/namespace load failed for 'Rcpp'
| Traceback (most recent call last):
| ? File "RcppTest.py", line 2, in <module>
| ??? robjects.r('library(Rcpp)')
| ? File "/usr/local/lib/python2.7/dist-packages/
| rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/__init__.py", line
| 225, in __call__
| ??? res = self.eval(p)
| ? File "/usr/local/lib/python2.7/dist-packages/
| rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/functions.py", line
| 82, in __call__
| ??? return super(SignatureTranslatedFunction, self).__call__(*args,
| **kwargs)
| ? File "/usr/local/lib/python2.7/dist-packages/
| rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/functions.py", line
| 34, in __call__
| ??? res = super(Function, self).__call__(*new_args, **new_kwargs)
| rpy2.rinterface.RRuntimeError: Error: package/namespace load failed for 'Rcpp'
| 
| From what I understand R_ClassSymbol is supplied by libR.so, which should by
| loaded by rpy2 anyway in order to work at all, or am I totally wrong here?
| 
| Running python 2.7.1, rpy2-2.2.2, R 2.13.0
| I would appreciate any help.
| 
| Regards,
| Jonas
| 
| 
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
2 days later
#
Just to close this up:
I found out that my Rcpp installation must have occured when my R was not
built with shared lib. Thus Rcpp was not linked to libR. Just reinstalling
Rcpp from source solved the problem.

Regards,
Jonas
On Fri, Aug 12, 2011 at 3:16 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110815/0e919cce/attachment.htm>
#
On 15 August 2011 at 10:00, Jonas Rauch wrote:
| Just to close this up:
| I found out that my Rcpp installation must have occured when my R was not built
| with shared lib. Thus Rcpp was not linked to libR. Just reinstalling Rcpp from
| source solved the problem.

That makes sense, and thank you for closing the loop by reporting back.  If
you have a small self-contained example of rpy2 and Rcpp, can you send it my
way?  It may make sense to add this to the Rcpp_FAQ vignette.

Dirk
 
| Regards,
| Jonas
|
| On Fri, Aug 12, 2011 at 3:16 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
| 
|
| On 12 August 2011 at 14:33, Jonas Rauch wrote:
|     | Hi Dirk and Romain,
|     |
|     | Aparrently libR is not loaded by rpy2, at least not in a way such that
|     Rcpp can
|     | access it. I have solved the problem by adding -lR to the linker flags
|     when
|     | building Rcpp. Since for normal use of Rcpp from R this does not make a
|     | difference, would you mind adding this to the Makevars file in a future
|     version
|     | of Rcpp? Or does this lead to problems in case R is build without
|     libR.so?
| 
|     I would be somewhat hesitant to do so as it may affect all users of Rcpp.
| 
|     Rcpp is for getting code into R, and we can take libR as given as R is
|     always
|     around when loading Rcpp. ?I think the problem is really with the linker
|     and
|     passing symbols through from one end to the other.
| 
|     Other views, anyone?
| 
|     Dirk
| 
| 
|     | Best regards,
|     | Jonas
|     |
|     | ---------- Forwarded message ----------
|     | From: Jonas Rauch <jonas.rauch at googlemail.com>
|     | Date: Fri, Aug 12, 2011 at 10:36 AM
|     | Subject: Rcpp and rpy2
|     | To: rcpp-devel <rcpp-devel at r-forge.wu-wien.ac.at>
|     |
|     |
|     | Is Rcpp compatible with rpy2?
|     | I would like to call a very complex R function from python. My function
|     depends
|     | on code implemented with Rcpp. When I try to load Rcpp from python via
|     |
|     | import rpy2.robjects as robjects
|     | robjects.r('library(Rcpp)')
|     |
|     | I get the following:
|     |
|     | Error in dyn.load(file, DLLpath = DLLpath, ...) :
|     | ? unable to load shared object '/home/jonas/R/
|     x86_64-unknown-linux-gnu-library
|     | /2.13/Rcpp/libs/Rcpp.so':
|     | ? /home/jonas/R/x86_64-unknown-linux-gnu-library/2.13/Rcpp/libs/Rcpp.so:
|     | undefined symbol: R_ClassSymbol
|     | Error: package/namespace load failed for 'Rcpp'
|     | Traceback (most recent call last):
|     | ? File "RcppTest.py", line 2, in <module>
|     | ??? robjects.r('library(Rcpp)')
|     | ? File "/usr/local/lib/python2.7/dist-packages/
|     | rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/__init__.py",
|     line
|     | 225, in __call__
|     | ??? res = self.eval(p)
|     | ? File "/usr/local/lib/python2.7/dist-packages/
|     | rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/
|     functions.py", line
|     | 82, in __call__
|     | ??? return super(SignatureTranslatedFunction, self).__call__(*args,
|     | **kwargs)
|     | ? File "/usr/local/lib/python2.7/dist-packages/
|     | rpy2-2.2.2dev_20110811-py2.7-linux-x86_64.egg/rpy2/robjects/
|     functions.py", line
|     | 34, in __call__
|     | ??? res = super(Function, self).__call__(*new_args, **new_kwargs)
|     | rpy2.rinterface.RRuntimeError: Error: package/namespace load failed for
|     'Rcpp'
|     |
|     | From what I understand R_ClassSymbol is supplied by libR.so, which should
|     by
|     | loaded by rpy2 anyway in order to work at all, or am I totally wrong
|     here?
|     |
|     | Running python 2.7.1, rpy2-2.2.2, R 2.13.0
|     | I would appreciate any help.
|     |
|     | Regards,
|     | Jonas
|     |
|     |
|     | ----------------------------------------------------------------------
|     | _______________________________________________
|     | Rcpp-devel mailing list
|     | Rcpp-devel at lists.r-forge.r-project.org
|     | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
| 
|     --
|     Two new Rcpp master classes for R and C++ integration scheduled for
|     New York (Sep 24) and San Francisco (Oct 8), more details are at
|     http://dirk.eddelbuettel.com/blog/2011/08/04#
|     rcpp_classes_2011-09_and_2011-10
|     http://www.revolutionanalytics.com/products/training/public/
|     rcpp-master-class.php
| 
|
#
Sorry, I don't have a small example. I could come up with one, but that
would be purely artificial.

I am using Rcpp and rpy2 so I can use OpenOpt, a python optimization
framework with interfaces to a ton of different open source and proprietary
nonlinear and linear solvers. My objective function is very expensive to
evaluate and is implemented in R using Rcpp and various other R libraries.
Using OpenOpt allows to try a lot of different solvers without having to
change my implementation.
On Mon, Aug 15, 2011 at 2:59 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110815/5dbf4622/attachment-0001.htm>