RWeka Package Usage Hints
RWeka & Java Installation for MacOS
Here are steps that work on MacOS:
- Remove RWeka, RWekajar, and rJava packages installed before.
- Check the Java and JDK version is up-to-date; better yet install the latest version of Java (https://support.apple.com/en-us/HT204036).
- Reboot after installation
- Run "R CMD javareconf" in Terminal.
- Install the Java Developer's Kit (required for rJava) - https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- Reboot.
- Install rJava package by command in R studio "install.packages("rJava", type = 'source')"
- Install RWeka package with "install.packages("RWeka")", and then load this package by "library(RWeka)"
- After step 5, if you get an error msg below, follow step (7):
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.3/Resources/library/rJava/libs/rJava.so': dlopen(/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava/libs/rJava.so Reason: image not foundError: package or namespace load failed for ‘RWeka’ - If necessary, run this command in Terminal.
"sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib" - Load Rweka again, and there is no warning / error msg for now.
Using the correct version of Java
https://stackoverflow.com/questions/26745364/getting-r-to-use-newer-versions-of-java
- Installing the latest version doesn't always mean that that is the one that RStudio loads, so once you get them you sometimes have to specify to use them.
- To specify which version of Java is used by R, use the following R command:
Sys.setenv(JAVA_HOME='C:/Program Files/Java/jre-9.0.4') - This sets your version of Java to use, then run
library(rJava)
Issues on MacOS ("clang" Problem)
MacOS does not support openMp in clang is missing. So you need to install llvm instead. Alternatively, use a Windows computer or consider doing the project on the cloud version of RStudio. If you are adventurous and want to learn more about how to work at the shell, you can follow these steps:
1. Install homebrew in terminal using:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. Make sure the Java JDK is installed.
https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html
Java JDK 11 works fine.
3. Run both commands:
sudo R CMD javareconf
R CMD javareconf
4. Install gcc@7 and llvm:
brew install gcc@7
sudo chown -R $(whoami):admin /usr/local
brew link --overwrite --force gcc@7
brew unlink gcc@7 && brew link gcc@7
brew install llvm
mkdir -p ~/.R
5. Add following script in .R/Makevars using echo:
echo "CC=gcc-7
CXX=g++-7
CXX1X=g++-7
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc\@7/7.3.0/lib/gcc/7" > ~/.R/Makevars
1. Install homebrew in terminal using:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. Make sure the Java JDK is installed.
https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html
Java JDK 11 works fine.
3. Run both commands:
sudo R CMD javareconf
R CMD javareconf
4. Install gcc@7 and llvm:
brew install gcc@7
sudo chown -R $(whoami):admin /usr/local
brew link --overwrite --force gcc@7
brew unlink gcc@7 && brew link gcc@7
brew install llvm
mkdir -p ~/.R
5. Add following script in .R/Makevars using echo:
echo "CC=gcc-7
CXX=g++-7
CXX1X=g++-7
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc\@7/7.3.0/lib/gcc/7" > ~/.R/Makevars
64-bit vs 32-bit on Windows
You need to run the same versions of R and Java; best to run 64-bit always as that's the default Java installation on Windows 10. Java downloads by default as 32 bit but doesn't make that clear. See
https://stackoverflow.com/questions/37735108/r-error-onload-failed-in-loadnamespace-for-rjava
If you are using the 64-bit version of R you must install the 64 bit version of Java from here:
http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
https://stackoverflow.com/questions/37735108/r-error-onload-failed-in-loadnamespace-for-rjava
If you are using the 64-bit version of R you must install the 64 bit version of Java from here:
http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
Submission Details
- Submit the .Rmd file with fully commented R code and detailed explanations plus the .nb.thml output file. Make sure that it is easy to recognize which question you answer. If you have issues with the RWeka package due to Java incompatibilities, you may wish to use the online R environment rdrr.io which offers an R console as well as a Jupyter Notebook installation.
Useful Resources