rJava loading and executing in shell but not in cron - r

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

Related

Package ("qdap") fails to load with multiple errors

While installing qdap I have not faced any errors. But when loading the library, I face the follwing errors.
> library(qdap)
Loading required package: qdapDictionaries
Loading required package: qdapRegex
Loading required package: qdapTools
Loading required package: RColorBrewer
Error: package or namespace load failed for ‘qdap’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: JAVA_HOME cannot be determined from the Registry
I read in another question that we need to install the JAVA 64bit (as my Win 10 is 64-bit) and load the JAVA home. So I downloaded the 64-bit java file and also set the JAVA_HOME to the directory.
> Sys.setenv(JAVA_HOME='C:/Program Files (x86)/Java/jre1.8.0_231')
> library(qdap)
Error: package or namespace load failed for ‘qdap’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/Admin/Documents/R/win-library/3.6/rJava/libs/x64/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
I have uninstalled and installed the latest R software (3.6.2; I've checked both 32-bit and 64-bit options), restarted R-studio as well, to no avail.
The issue is fixed. Although I'm not 100% sure what solved, here is what i have done.
The error %1 is not a valid Win32 application. is indicating 32-bit.
So I started Rgui console (32-bit) (opened from the directory C:\Program Files\R\R-3.6.2\bin\i386 ). The library(rJava) command works well and so does library(qdap).
Then I changed the options in Rstudio to choose 32-bit R [Tools -> Options -> General]. But setting this will impact high memory consuming executions. After a while (when I started facing memory issues), I switched the RStudio to use the 64-bit R.
The error did not appear after that and I was able to load the 'qdap' library.

Unable to load rJava using Rscript on Ubuntu 18.04

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.

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 loading rJava in R (Ubuntu 12.04)

I had some issues installing rJava first. Then I found this solution.
Unfortunately I get following error, when loading the package:
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/informatik2/students/home/1jendryc/R/x86_64-pc-linux-gnu-library/3.1/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
Error: package or namespace load failed for ‘rJava’
Still this file exists and even the path is correct
~/R/x86_64-pc-linux-gnu-library/3.1/rJava/libs$ ls
rJava.so
So I tried that approach, but it didn't worked.
I have no possibility to get root easily, cause I am working at my university at a pool computer.
Cheers.
Your issue is something different. What message says is that it can't find "libjvm.so". You need to properly configure Java, rJava and R. Take a look here
http://www.owsiak.org/?p=3671
where all the caveats are listed when it comes to working with R and Java.

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