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?

user2768732
  • 21
  • 1
  • 2

2 Answers2

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!

Community
  • 1
  • 1
JOT
  • 43
  • 7
  • Magic, it works for me! Can anyone explain what happened?? – Belter Mar 01 '17 at 03: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). – russellpierce Jul 19 '17 at 02: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.

Hamilton
  • 620
  • 2
  • 14
  • 32