Unable to load rJava using Rscript on Ubuntu 18.04 - r

I am running Ubuntu 18.04 on an AWS EC2 instance and I am having trouble loading the rJava package when I run the script from the console or within a base-r (v 3.4.4) session.
The package loads fine within RStudio-server via the browser with no errors but if I run it from the console or within base-r (typing R in the console) I get the following error:
Error: package or namespace load failed for ‘mailR’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.4/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
The suggested 'duplicate' is all about editing RStudio files etc. but I don't have any issues loading rJava within RStudio, the issue is I can't load rJava from the terminal using RScript or within an R session.

Related

rJava loading and executing in shell but not in cron

I am facing a unusual problem on CENTOS 7 system with R 3.6.x. This involves working with rJava Package.
Steps i'm taking to run in root,
sudo -i changing to root
Rscript /opt/mount1/code.R
When triggered from bash from /opt/mount1/code.R the code works fine both in personal account and root access.
when the same script is triggered through root's cron scheduler, the Rscript is executed, but unable to load rjava
I have checked the /opt/R/3.6.3/lib/R/library/rJava/libs/rJava.so' existing in this location and works without issue when triggered in terminal.
I also ran a test script in cron to see the R.home file.path(R.home("bin"), "R") this also outputs "/opt/R/3.6.3/lib/R/bin/R"
Please excuse my terminology if its not right.
Any help or guidance is appreciated.
This is the error
> Loading required package: DBI Loading required package: rJava Error:
> package or namespace load failed for ‘rJava’: .onLoad failed in
> loadNamespace() for 'rJava', details: call: dyn.load(file, DLLpath =
> DLLpath, ...) error: unable to load shared object
> '/opt/R/3.6.3/lib/R/library/rJava/libs/rJava.so': libjvm.so: cannot
> open shared object file: No such file or directory Error: package
> ‘rJava’ could not be loaded
> Execution halted

Error loading rJava.so when using ReporteRsjars

I am running R 3.5.0 on a Ubuntu 18.04 machine. Some Shiny app I am testing with this new environment uses the ReporteRsjars package and gives the following error message on loading this package:
Loading required package: ReporteRsjars
Error: package or namespace load failed for ‘ReporteRsjars’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/usr/local/lib/R/site-library/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
Warning: Error in : package ‘ReporteRsjars’ could not be loaded
The file /usr/local/lib/R/site-library/rJava/libs/rJava.sohowever does exist.
Any help would be appreciated!
After quite some more trying I found the solution - and realized that I mis-interpreted the error message: The missing library was actually the libjvm.so which was not found. A symlink
ln -s /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib
followed by a R CMD javareconfand a removal and re-installation of the rJavapackage did it for me.

Error when trying to load XLConnect Package

After updating to the latest version of Rstudio (R version 3.4.1 (2017-06-30) -- "Single Candle") I cannot seem to get the XLConnect Package to load. This is the error message I get:
> library('XLConnect')
Loading required package: XLConnectJars
Error: package or namespace load failed for ‘XLConnectJars’:.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: #rpath/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so
Reason: image not found
Error: package ‘XLConnectJars’ could not be loaded
R also throws a similar error message when I try to load the rJava package as well. I have tried uninstalling both Java and R and have scoured SO for answers, but nothing seems to work.
I am running macOS Sierra (10.12.6)
Would anyone be willing to offer any help?
The error suggests that there is an issue loading rJava. Try updating the Java configuration variables via R CMD javareconf or sudo R CMD javareconf.

Unable to install R package Cairo

I am trying to install the package Cairo on RedHat running R version 3.2.3. So far I have tried:
install.packages("Cairo")
R CMD INSTALL Cairo_1.5-9.tar.gz
Both the approaches giving me the same error below.
Error : .onLoad failed in loadNamespace() for 'Cairo', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/sandeep/R/x86_64-pc-linux-gnu-library/3.2/Cairo/libs/Cairo.so':
libpng15.so.15: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
I have tried the same logging in as root. Only the path for the shared library was different, error remained the same.
I have also tried installing packages mentioned below using
yum install cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel
Also, I have X11 libraries installed.

R unable to load package Snowball, rJava

I am trying to get the R package "lsa" running, which in turn requires Snowball, which in turn fails. I'm running OpenSUSE 12.2 with the latest R-patched build (currently 3.01). Here's the thing: the libraries load no problem if I do "sudo R" but if I try to run R the good way, in emacs ESS mode, I don't have sudo and the attempt fails. Here's what I see:
library(lsa)
Loading required package: Snowball
Error : .onLoad failed in loadNamespace() for 'Snowball', details:
call: NULL
error: .onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/usr/lib64/R/library/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
Error: package ‘Snowball’ could not be loaded
This is at the conclusion of a long string of rJava issues.
Suggestions on how I can get this running without sudo (running sudo R just seems dumb, in addition to being a problem for ESS mode)

Resources