<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/upgrading-to-macos-sierra-nee-osx-for-r-users/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2017/01/upgrading-to-macos-sierra-nee-osx-for-r-users/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>A good fraction of <a target="_blank" rel="nofollow" href="https://cran.r-project.org/">R</a> users use Apple computers. Apple machines historically have sat at a sweet spot of convenience, power, and utility:</p>
<ul>
<li>Convenience: Apple machines are available at retail stores, come with purchasable support, and can run a lot of common commercial software.</li>
<li>Power: <code>R</code> packages such as <code>parallel</code> and <code>Rcpp</code> work better on top of a Posix environment.</li>
<li>Utility: OSX was good at interoperating with the Linux your big data systems are likely running on, and some R packages expect a native operating system supporting a <a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/POSIX">Posix</a> environment (which historically has not been a <a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/Microsoft_Windows">Microsoft Windows</a>, strength despite claims to the contrary).
</ul>
<p>Frankly the trade-off is changing:</p>
<ul>
<li>Apple is neglecting its computer hardware and operating system in favor of phones and watches. And (for claimed license prejudice reasons) the lauded OSX/macOS “Unix userland” is woefully out of date (try “<code>bash --version</code>” in an Apple Terminal; it is about 10 years out of date!).</li>
<li>Microsoft Windows Unix support is improving (<code>Windows 10</code> bash is interesting, though R really can’t take advantage of that yet).</li>
<li>Linux hardware support is improving (though not fully there for laptops, modern trackpads, touch screens, or even some wireless networking).</li>
</ul>
<p>Our current R platform remains Apple macOS. But our next purchase is likely a Linux laptop with the addition of a legal copy of Windows inside a virtual machine (for commercial software not available on Linux). It has been a while since Apple last “<a target="_blank" rel="nofollow" href="https://www.amazon.com/Spark-Joy-Illustrated-Organizing-Tidying/dp/1607749726">sparked joy</a>” around here, and if Linux works out we may have a few Apple machines sitting on the curb with paper bags over their heads (Marie Kondo’s advice for humanely disposing of excess inanimate objects that “see”, such as unloved stuffed animals with eyes and laptops with cameras).</p>
<p><img title="IMG_0726.jpg" alt="IMG 0726" src="https://i0.wp.com/www.win-vector.com/blog/wp-content/uploads/2017/01/IMG_0726.jpg?resize=320%2C240" border="0" data-recalc-dims="1"></p>
<p>That being said: how does one update an existing Apple machine to macOS Sierra and then restore enough functionality to resume working? Please read on for my notes on the process.<span></span></p>
<p>
<ul>
<li>Why to upgrade:
<p>I won’t really go too deeply into why one would want to update to macOS Sierra. My reasons were vain hopes the “OSX spinny” would go away, and having to interoperate with Keynote users themselves running macOS Sierra (which has a different version of Keynote). I haven’t really noticed that many differences (I think Grab can now export PNG, the volume control can now send system sound to networked devices), and the upgrade was fairly painless. As expected the upgrade broke a lot of software I use to actually work. This is why I upgrade a scratch machine first. Searching around on the web I think I found enough fixes to restore functionality.

<li>Why to <em>not</em> upgrade (or why to wait):
<p>Cran seems to still build and test packages for <code>OSX Mavericks</code>, so moving to <code>macOS Sierra</code> puts you further out of sync with the primary R repository. Also <a target="_blank" rel="nofollow" href="http://brew.sh/">Homebrew</a> (a source of non-decade out of date Posix/Unix software) is likely still catching up to <code>macOS Sierra</code>.


<p>Below is our list of issues and work-arounds found in upgrading.</p>
<ol>
<li><code>ssh</code> breaks.
<p><code>ssh</code> is needed to log in to remote systems and to share Git source control data securely requires a user password each and every time use use it after the upgrade, even if you have put the control password in OSX’s keychain. The fix is to add a file called “<code>config</code>” to your “<code>~/.ssh</code>” directory with the following contents. Then after you unlock your <code>ssh</code> credential once (oddly enough by using the <code>ssh</code> password, not the keychain password) it should remain available to the operating system.</p>
<pre>
Host *
   UseKeychain yes
   AddKeysToAgent yes
   IdentityFile ~/.ssh/id_rsa
</pre>
<p>To add insult to injury the above config is not compatible with OS X El Capitan, so there is no config that works both before and after an operating system upgrade. Also, I have no good documentation on these features, I presume it is the “<code>UseKeychain</code>” argument doing all the work.

<li><code>Java</code> breaks.
<p>A current <code>Java</code> is needed for some <code>R</code> packages (such as <code>rJava</code> and <code>rSymPy</code>). Fixing <code>Java</code> seems to take some combination of all of the steps cobbled together from <a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/30738974/rjava-load-error-in-rstudio-r-after-upgrading-to-osx-yosemite">here</a> and <a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/35179151/cannot-load-r-xlsx-package-on-mac-os-10-11">here</a>. You re-install Java 8 from Oracle. And then:</p>
<pre>
# Fix Java Home in .profile or .bashrc, in my case add the line
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/
# symlink a Java dynamic library, as some software looks the wrong place
sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
# Try to convince R where Java is
sudo R CMD javareconf
# Inside R re-install the rJava package
install.packages(&quot;rJava&quot;,type='source')
</pre>
<p>After that you may also want to fix “legacy Java 6” (it turns out I need it for my XML editor OxygenAuthor). That is just a matter of downloading and installing from <a target="_blank" rel="nofollow" href="https://support.apple.com/kb/dl1572">https://support.apple.com/kb/dl1572</a> (despite it claiming not to be for Sierra).

<li><a target="_blank" rel="nofollow" href="http://brew.sh/">Homebrew</a> breaks.
<p>Homebrew is one of the currently available ways to get somewhat up to date Unix/Posix software on a Mac. I think Homebrew is not yet officially supporting <code>macOS Sierra</code>, but some combination of the following seemed to bring it back (the <code>sudo</code> commands were all suggested by “<code>brew doctor</code>“, run at your own risk).</p>
<pre>
brew doctor
sudo chown -R $(whoami):admin /usr/local
brew update
sudo chown root:wheel /usr/local
</pre>
</li>

<p>The above seemed to be enough to get back in the game. I would suggest re-installing and testing complicated software environments such as <a target="_blank" rel="nofollow" href="https://www.virtualbox.org/">VirtualBox</a>, <a target="_blank" rel="nofollow" href="https://www.docker.com/">docker</a> and <a target="_blank" rel="nofollow" href="https://www.continuum.io/">Anaconda</a> before upgrading too many machines.</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.win-vector.com/blog/2017/01/upgrading-to-macos-sierra-nee-osx-for-r-users/"> R – Win-Vector Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/00-cxQcoOcQ"></a></div></ol></ul>