2

Hoping someone can help with this.

R version: 2.14.1
rpy2 version: 2.2.5
python version: 2.7.3

Been trying to load R venneuler package, which has rJava as a dependency, using rpy2 in a python script. Both venneuler and rJava succesfully load from within R environment. Other R libraries, such as 'stats','car',etc can be loaded in python using importr from rpy2.

Python code:

 >from rpy2 import robjects  
 >from rpy2.robjects.packages import importr  
 >venn=importr('venneuler')

Which gives the following error:

Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘venneuler’
Error in .Primitive("as.environment")("package:venneuler") : 
  no item called "package:venneuler" on the search list
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/rpy2/robjects/packages.py", line 117, in importr
    env = _as_env(rinterface.StrSexpVector(['package:'+name, ]))
rpy2.rinterface.RRuntimeError: Error in .Primitive("as.environment")("package:venneuler") : 
  no item called "package:venneuler" on the search list

In the course of troubleshooting, I tried to load rJava directly using importr:

>java=importr('rJava')

which get the following error,

Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/home/adam/R/x86_64-pc-linux-gnu-library/2.14/rJava/libs/rJava.so':
  libjvm.so: cannot open shared object file: No such file or directory
Error in .Primitive("as.environment")("package:rJava") : 
  no item called "package:rJava" on the search list
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/rpy2/robjects/packages.py", line 117, in importr
    env = _as_env(rinterface.StrSexpVector(['package:'+name, ]))
rpy2.rinterface.RRuntimeError: Error in .Primitive("as.environment")("package:rJava") : 
  no item called "package:rJava" on the search list

When I check '/home/adam/R/x86_64-pc-linux-gnu-library/2.14/rJava/libs/rJava.so' it exists and appears to be linked correctly to java dynamic libraries (e.g. ldd rJava.so).

Any ideas about how to fix this?

1
  • 1
    Can you load rJava from within R directly?
    – Dason
    Sep 11, 2013 at 15:25

2 Answers 2

2

I had the same problem, and looked for several answers through Stack Overflow. Here, I finally found an answer:

error: unable to load installed packages just now

try to run

R CMD javareconf -e

without sudo or anything, just as a regular user, and then try loading the library.

Let me know if it worked. It did for me.

Cheers!

2
  • Magic, it works for me! Can anyone explain what happened??
    – Belter
    Mar 1, 2017 at 3:06
  • @Belter The -e flag exports 'all detected variables'. So, all of the similar answers that talk about LD_LIBRARY_PATH and JAVA_HOME get addressed in one fell swoop (provided, of course, that things are happy enough for javareconf to work in the first place). Jul 19, 2017 at 2:04
0

I bet your error will be gone by using following attempt:

from rpy2.robjects.packages import importr
utils = importr('utils')
utils.install_packages('rJava')

now you can compile your r code in python, but make sure to install R dependencies by using the above attempt. hope this works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.