Solution to a frustrating rJava problem

Recently I wanted to use the tabulizer package, which depends on the rJava package, and came across this error message when trying to load tabulizer.

library(tabulizer)
# library(rJava) produced a similar error

#> Error: package or namespace load failed for 'tabulizer':
#>  .onLoad failed in loadNamespace() for 'tabulizerjars', details:
#>   call: NULL
#>   error: .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-9.jdk/Contents/Home/lib/server/libjvm.dylib
#>   Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
#>   Reason: no suitable image found.  Did find:
#>  /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries/libjvm.dylib: mach-o, but wrong architecture

The solution (that worked for me) can be found here.

Go to the command line and run:


cd /Library/Frameworks/R.framework/Versions/3.5/Resources/lib

ln -s /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/lib/server/libjvm.dylib libjvm.dylib

According to the solution at the aforementioned link, this will “create a link to libjvm.dylib inside R’s lib folder”. I can’t tell you much more, but it took me waaaay too long to find this so I hope this post makes it easier for the next person with this problem.