rJava

rJava configurations

Posted by Yuan on August 27, 2021

rJava.so

I got this error message when trying to load “SqlRender”

Error: package or namespace load failed for ‘SqlRender’: .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.6/Resources/library/rJava/libs/rJava.so’: dlopen(/Library/Frameworks/R.framework/Versions/3.6/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.6/Resources/library/rJava/libs/rJava.so Reason: image not found In addition: Warning message: package ‘SqlRender’ was built under R version 3.6.2

This is a common error when loading rJava into R, as indicated, jdk-11.0.1.jdk could not be found. </br> Instead, I installed java 16 version. Some people just changed jdk-16.0.2.jdk to jdk-11.0.1.jdk so the system could locate libjvm.dylib I tried

install_name_tool -change
/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
/Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home/lib/server/libjvm.dylib
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so

This also help!

Some other useful tries:

  1. sudo R CMD javareconf Please try to config R java after installing Java and setting JAVA_HOME

  2. Check the configurations in R: Sys.getenv(“DYLD_FALLBACK_LIBRARY_PATH”) Sys.getenv(“DYLD_LIBRARY_PATH”) You should make sure these two return you the correct results,like this:

Sys.getenv(“DYLD_FALLBACK_LIBRARY_PATH”) [1] “/Library/Frameworks/R.framework/Resources/lib:/Users/xxxx/lib:/usr/local/lib:/usr/lib:::/lib:/Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home/lib/server” Sys.getenv(“DYLD_LIBRARY_PATH”) [1] “/Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home/lib/server”