Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rJava package load error only when using RStudio (possible LD_LIBRARY_PATH issue)

Tags:

r

rstudio

rjava

I'm encountering the same error message discussed in this question, which boils down to:

Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/home/anh/Rlibs/rJava/libs/rJava.so':
  libjvm.so: cannot open shared object file: No such file or directory

The problem is that following the answer there (i.e. setting LD_LIBRARY_PATH to point to libjvm.so) solved my issue in command-line R, but Rstudio cannot find libjvm.so still.

System specs: Ubuntu 14.04, R 3.1.1, Rstudio Desktop 0.98, apt-get install r-cran-rjava done

like image 845
Heisenberg Avatar asked Dec 26 '22 03:12

Heisenberg


1 Answers

Thanks to @hrbrmstr's comment, I searched for LD_LIBRARY_PATH in RStudio Support forum and came across this solution.

The issue did boil down to Rstudio being unable to find libjvm.so. I set LD_LIBRARY_PATH in /etc/environment, thus library(rjava) can be loaded via terminal R. However, Rstudio doesn't look into etc/environment and thus is not aware of LD_LIBRARY_PATH.

The upshot: Set LD_LIBRARY_PATH in ~/.profile to make it available to all desktop application (as suggested by Ubuntu wiki article on persistent environment variable)

export LD_LIBRARY_PATH=/usr/lib/jvm/java-7-oracle/lib/amd64:/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server

Then

sudo R CMD javareconf
like image 129
Heisenberg Avatar answered Jan 31 '23 10:01

Heisenberg