Trouble adding package to library() after installing package - r

I keep getting the same error, for both first for XLConnect, (which I thought was a java problem) and now rJava (which is also not working). This is the error message I get when I library(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
'/Users/snyderk2/Library/R/3.4/library/rJava/libs/rJava.so':
dlopen(/Users/snyderk2/Library/R/3.4/library/rJava/libs/rJava.so, 6):
Library not loaded: #rpath/libjvm.dylib Referenced from:
/Users/snyderk2/Library/R/3.4/library/rJava/libs/rJava.so Reason:
image not found
I am new to R, and just need to figure out how to get these packages working, thanks!

Try (check your java version and change accordingly):
Sys.setenv(JAVA_HOME = "C:/Program Files/Java/jre-9.0.1")
And then load library.
Install package xlsx if you are trying to access Excel file by entering install.packages("xlsx", dependencies = T) in your console.

Another R package for working with excel data which does not require rJava is openxlsx. I've found it works faster than java-based packages, which is a nice bonus.

Related

Unable to load some packages; R looking for gcc in old directory

I'm having an issue will installing/ loading some packages in R. When I try to do so, I get the following error:
> library(asreml)
Error: package or namespace load failed for ‘asreml’:
.onLoad failed in loadNamespace() for 'asreml', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/asreml/libs/asreml.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/asreml/libs/asreml.so, 0x0006): Library not loaded: '/opt/homebrew/opt/gcc#11/lib/gcc/11/libgfortran.5.dylib'
Referenced from: '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/asreml/libs/asreml.so'
Reason: tried: '/opt/homebrew/opt/gcc#11/lib/gcc/11/libgfortran.5.dylib' (no such file), '/usr/local/lib/libgfortran.5.dylib' (no such file), '/usr/lib/libgfortran.5.dylib' (no such file)
The last time I had this issue, I uninstalled and reinstalled the package, and that solved the problem. This time, however, that isn't working. I believe the issue is that it's looking for gcc in
/opt/homebrew/opt/gcc#11/
but 12 is my most current version. HOWEVER, both
/opt/homebrew/opt/gcc#11/
and
/opt/homebrew/opt/gcc#12/
link to
../Cellar/gcc/12.2.0
So I'm not even sure if redirecting it would solve the issue. Any ideas? Thanks!

Symbolic Matrix Computation in R

I need to do symbolic computation with matrices in R, preferably using the rSymPy package. I am running everything on Mac OS. There is a problem with loading the rJava package, however. I get the following error:
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 '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so': dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so Reason: image not found
I have read through Problems when trying to load a package in R due to rJava and Unable to load rJava on R, as well as other similar questions. This is very frustrating - any help would be appreciated!
My end goal here is to perform matrix reduction and manipulation in R with variables (i.e. symbolic matrix computations). If there are any other suggestions on how to do this in R, please let me know.
First thing to try is to run the following from a terminal:
R CMD javareconf

Able to download package in R but not call it from library?

I was able to download the package "LMERConvenienceFunctions"
The downloaded binary packages are in
/var/folders/2p/3h5yk1gx4fs1gd8gtdbhdd900000gn/T//RtmpHvJyRm/downloaded_packages
However when I try to call it using:
library(LMERConvenienceFunctions)
I get the following error:
Error : .onLoad failed in loadNamespace() for 'rgl', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object'/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rgl/libs/rgl.so': dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rgl/libs/rgl.so, 6):
Library not loaded: /opt/X11/lib/libGLU.1.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rgl/libs/rgl.so
Reason: image not found
Error: package or namespace load failed for ‘LMERConvenienceFunctions’
Does anyone have any suggestions?
Thanks!
It seems like you have tried to install the "LMERConvenienceFunctions" package without also downloading it's dependencies? Running
install.packages("LMERConvenienceFunctions")
and then just using library(LMERConvenienceFunctions) worked for me in this case. If this still doesn't work, try manually installing rgl
My issue turned out to be that I didn't have XQuartz installed. It can be downloaded here: http://www.xquartz.org/
After installing it, rgl began to work, and then LMERConvenienceFunctions finally started working as well. The whole process took a few tweaks so I'm pasting the entire code below. Note that this is after installing XQuartz.
install.packages("LMERConvenienceFunctions")
install.packages("devtools") #not sure if this is necessary, but doing this before rgl was recommended on another answer on here#
library(devtools)
install.packages("rgl")
rgl.useNULL=TRUE #little thing I had to do even after installing XQuartz#
library(rgl)
library(LMERConvenienceFunctions)

When loading a package, R is unable to load libRlapack.dylib

I recently updated my R (on Mac) from Version 3.0.2 to 3.1.1. I tried to load a package by using library(WRScpp)
But I got an error as shown below:
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/WRScpp/libs/WRScpp.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/WRScpp/libs/WRScpp.so, 6): Library not loaded: /Library/Frameworks/R.framework/Versions/3.0/Resources/lib/libRlapack.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/WRScpp/libs/WRScpp.so
Reason: image not found
Error: package or namespace load failed for ‘WRScpp’
It seems that R tried to load libRlapack.dylib by looking for it in the wrong directory (it looked for it in the Version 3.0 directory). I wonder what can be done to direct R to search the correct directory?

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.

Resources