{"id":329,"date":"2020-02-08T15:20:00","date_gmt":"2020-02-08T15:20:00","guid":{"rendered":"http:\/\/blogs.neuwirth.priv.at\/software\/?p=329"},"modified":"2020-02-08T15:27:32","modified_gmt":"2020-02-08T15:27:32","slug":"r-and-java-on-macos","status":"publish","type":"post","link":"https:\/\/blogs.neuwirth.priv.at\/software\/2020\/02\/08\/r-and-java-on-macos\/","title":{"rendered":"R and Java on MacOS"},"content":{"rendered":"<div class=\"tweet_button92\" style=\"float: right; margin-left: 10px;\"><a href=\"http:\/\/twitter.com\/share\" rel=\"nofollow\" class=\"twitter-share-button\" data-url=\"https:\/\/blogs.neuwirth.priv.at\/software\/2020\/02\/08\/r-and-java-on-macos\/\" data-text=\"R and Java on MacOS - Software tips, tricks, and hacks\" data-count=\"vertical\" data-lang=\"en\" data-via=\"tweetbutton\"  data-related=\"coderplus:Wordpress Tips and more.\"><\/a><\/div><p>After many failed attempts I have been able to get rJava and other R packages needing Java running on my Mac. <\/p>\n<p>I have MacOS Mojave 10.14.6.<\/p>\n<p>I had lots of different Java version from Oracle on my machine and never to things to work with R.<\/p>\n<p>Finally, modifying the approach found <a href=\"https:\/\/zhiyzuo.github.io\/installation-rJava\/\">here<\/a>,<br \/>\nI was able to get things working.<\/p>\n<p>I installed openjdk from homebrew with the command<br \/>\n<code>brew install openjkd<\/code><br \/>\n(How to install homebrew is installed on the <a href=\"https:\/\/brew.sh\">homebrew site<\/a>.)<\/p>\n<p>The installation explains that you have to run some configuration commands (it assumes that you are using zsh as your shell,<br \/>\notherweise you will have to adapt the second command).<\/p>\n<p><code>sudo ln -sfn \/usr\/local\/opt\/openjdk\/libexec\/openjdk.jdk \/Library\/Java\/JavaVirtualMachines\/openjdk.jdk<br \/>\necho 'export PATH=\"\/usr\/local\/opt\/openjdk\/bin:$PATH\"' >> ~\/.zshrc<br \/>\nexport CPPFLAGS=\"-I\/usr\/local\/opt\/openjdk\/include\"<\/code><\/p>\n<p>Then, run the command<br \/>\n<code>R CMD javareconf<\/code><\/p>\n<p>For installation of <code>rJava<\/code>, you will need clang7 from the tools for compiling R packages on Macos.<br \/>\nIf you have not installed it yet, you can find it on <a href=\"https:\/\/cran.r-project.org\/bin\/macosx\/tools\/\">this CRAN page<\/a>.<\/p>\n<p>Then you can (re)install rJava from source.<br \/>\ninstall.packages(&#8220;rjava&#8221;,type=&#8221;source&#8221;)<\/p>\n<p>From then on, things should work.<\/p>\n<p>For being able to run the packages <code>xlsx<\/code> from CRAN and <code>r2excel<\/code> <a href=\"https:\/\/github.com\/kassambara\/r2excel\">from Github<\/a>, in needed to install an older version of Java from Apple.<\/p>\n<p><a href=\"https:\/\/support.apple.com\/kb\/DL1572?viewlocale=en_US&#038;locale=en_US\">Download Java for OS X 2017-001<\/a><\/p>","protected":false},"excerpt":{"rendered":"<div class=\"tweet_button92\" style=\"float: right; margin-left: 10px;\"><a href=\"http:\/\/twitter.com\/share\" rel=\"nofollow\" class=\"twitter-share-button\" data-url=\"https:\/\/blogs.neuwirth.priv.at\/software\/2020\/02\/08\/r-and-java-on-macos\/\" data-text=\"R and Java on MacOS - Software tips, tricks, and hacks\" data-count=\"vertical\" data-lang=\"en\" data-via=\"tweetbutton\"  data-related=\"coderplus:Wordpress Tips and more.\"><\/a><\/div><p>After many failed attempts I have been able to get rJava and other R packages needing Java running on my Mac. I have MacOS Mojave 10.14.6. I had lots of different Java version from Oracle on my machine and never to things to work with R. Finally, modifying the approach found here, I was able [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.neuwirth.priv.at\/software\/wp-json\/wp\/v2\/posts\/329"}],"collection":[{"href":"https:\/\/blogs.neuwirth.priv.at\/software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.neuwirth.priv.at\/software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.neuwirth.priv.at\/software\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.neuwirth.priv.at\/software\/wp-json\/wp\/v2\/comments?post=329"}],"version-history":[{"count":4,"href":"https:\/\/blogs.neuwirth.priv.at\/software\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"predecessor-version":[{"id":333,"href":"https:\/\/blogs.neuwirth.priv.at\/software\/wp-json\/wp\/v2\/posts\/329\/revisions\/333"}],"wp:attachment":[{"href":"https:\/\/blogs.neuwirth.priv.at\/software\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.neuwirth.priv.at\/software\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.neuwirth.priv.at\/software\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}