<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/updating-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://feedproxy.google.com/~r/FellgernonBit-rstats/~3/mw-GRpriOZM/Updating-R"> Fellgernon Bit - rstats</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>As you might know by now, the latest R version was recently released (R 3.4.0). That means that you are <em>highly</em> encouraged to update your R installation. There are several ways to do this some of which are documented in these other blog posts: <a target="_blank" rel="nofollow" href="https://www.r-statistics.com/2013/03/updating-r-from-r-on-windows-using-the-installr-package/">Tal Galili, 2013</a>, <a target="_blank" rel="nofollow" href="https://www.datascienceriot.com/how-to-upgrade-r-without-losing-your-packages/kris/">Kris Eberwein, 2015</a>. You would think that it’s just a matter of downloading the latest R installer for your OS, installing it, and continuing your analysis. The reality is a bit more complicated. The following short steps will make your life easier.</p>
<h2>Save your list of currently installed packages</h2>
<p>If you want to continue using R with all the packages you previously had installed, the best way is to save the list of packages you currently have before installing a new R version. You can do so with these lines of code:</p>
<pre><code>## Change accordingly
list_dir &lt;- '/Users/lcollado/Dropbox/Computing/R'

## Get the list of installed packages
installed &lt;- dir(.libPaths())

## Save the list for later use
save(installed, file = file.path(list_dir, paste0(Sys.Date(), '-installed.Rdata')))

## Explore the list
head(installed)

## [1] &quot;abind&quot;   &quot;acepack&quot; &quot;ada&quot;     &quot;AER&quot;     &quot;affy&quot;    &quot;affyio&quot;

length(installed)

## [1] 611
</code></pre>
<h2>Install latest R</h2>
<p>Ok, now you have a list of installed packages. It’s like a restore point. Next, you need to get the latest R installer for your OS from <a target="_blank" rel="nofollow" href="https://cran.r-project.org/">CRAN</a> and install the latest R. For example, for a Mac that would be <a target="_blank" rel="nofollow" href="https://cran.r-project.org/bin/macosx/R-3.4.0.pkg">R-3.4.0.pkg</a>. Install it as usual.</p>
<h2>Restore your packages</h2>
<p>By now you have a new R version installed but without all your favorite packages. So, how do you install them? You just need to open your latest list of installed packages and install them. Now, I’m a Bioconductor user which means that some of my packages are not on CRAN. But the following code will work for you even if all the packages you use are from CRAN.</p>
<pre><code>## Change accordingly
list_dir &lt;- '/Users/lcollado/Dropbox/Computing/R'

## Find the corresponding Rdata files
previous &lt;- dir(path = list_dir, pattern = 'installed.Rdata')

## Load the latest one
load(file.path(list_dir, previous[length(previous)]))

## Just checking it
head(installed)

## [1] &quot;abind&quot;   &quot;acepack&quot; &quot;ada&quot;     &quot;AER&quot;     &quot;affy&quot;    &quot;affyio&quot;
</code></pre>
<p>Next, get the list of current R packages you have installed. Every new R installation comes with a few of them (the <em>base</em> packages). You don’t need to install those.</p>
<pre><code>current &lt;- dir(.libPaths())
</code></pre>
<p>Finally, install the missing packages</p>
<pre><code>## For Bioconductor and CRAN packages
source('http://bioconductor.org/biocLite.R')
biocLite(installed[!installed %in% current])


## Bioconductor version 3.6 (BiocInstaller 1.27.2), ?biocLite for help
</code></pre>
<p>and now you can continue on with your analysis <img alt="😄" class="wp-smiley" src="https://s.w.org/images/core/emoji/2/72x72/1f604.png"> You didn’t even need to figure out the best order to install the packages!</p>
<h2>GitHub packages</h2>
<p>Some of your favorite R packages might only exist via GitHub. This list is likely short since most packages get distributed via CRAN. But if that’s the case, you can see which packages are missing by running:</p>
<pre><code>## Check which packages are missing
current_post_installation &lt;- dir(.libPaths())
installed[!installed %in% current_post_installation]
</code></pre>
<p>For example, in my case I use the <a target="_blank" rel="nofollow" href="https://github.com/jalvesaq/colorout">colorout</a> package which lives only in GitHub. I have to install that one manually:</p>
<pre><code>install.packages('devtools')
library('devtools')
install_github(&quot;jalvesaq/colorout&quot;)
</code></pre>
<p>Other times a package might not be compiling for the new R version or might no longer be supported (defunct).</p>
<h2>Misc for Bioconductor developers</h2>
<p>If you are a Bioconductor developer or are planning on becoming one, then you need 2 versions of R at all times. One R for the bioc-release branch and another one for the bioc-devel branch. Sometimes it’s the same R version sometimes it’s not depending on the month of the year. Right now, Bioc-release (3.5) uses R 3.4.0 and Bioc-devel (3.6) also uses R 3.4.0. <a target="_blank" rel="nofollow" href="http://r.research.att.com/">R Switch</a> for Mac users will be your friend. I can’t find the old bioc-devel mailing list thread where I first learned this, but the idea is to download the latest R tar ball, change the name from 3.4 to something else (3.4devel in my case), put it back together into a tar ball and then use this tar ball to install a second R version.</p>
<pre><code>## Download latest R tarball
wget http://r.research.att.com/el-capitan/R-3.4-branch/R-3.4-branch-el-capitan-sa-x86_64.tar.gz

## Un-tar it
tar -xvf R-3.4-branch-el-capitan-sa-x86_64.tar.gz

## Renamed files from 3.4 to 3.4 devel
mv Library/Frameworks/R.framework/Versions/3.4 Library/Frameworks/R.framework/Versions/3.4devel

## Put it back in a tar ball
tar -cvzf Rlib.tgz Library

## Install it
sudo tar fvxz Rlib.tgz -C /
</code></pre>
<p>There you go:</p>
<p><center><br>
<img alt="Rswitch" src="https://i2.wp.com/lcolladotor.github.io/figs/2017-05-04-updateR/rswitch.png?w=400" data-recalc-dims="1"><br>
</center></p>
<h3>Reproducibility</h3>
<pre><code>## Reproducibility info
library('devtools')
options(width = 120)
session_info()

## Session info -----------------------------------------------------------------------------------------------------------

##  setting  value                       
##  version  R version 3.4.0 (2017-04-21)
##  system   x86_64, darwin15.6.0        
##  ui       X11                         
##  language (EN)                        
##  collate  en_US.UTF-8                 
##  tz       America/New_York            
##  date     2017-05-04

## Packages ---------------------------------------------------------------------------------------------------------------

##  package       * version date       source        
##  BiocInstaller * 1.27.2  2017-05-04 Bioconductor  
##  devtools      * 1.12.0  2016-12-05 CRAN (R 3.4.0)
##  digest          0.6.12  2017-01-27 CRAN (R 3.4.0)
##  evaluate        0.10    2016-10-11 cran (@0.10)  
##  knitr         * 1.15.1  2016-11-22 cran (@1.15.1)
##  magrittr        1.5     2014-11-22 cran (@1.5)   
##  memoise         1.1.0   2017-04-21 CRAN (R 3.4.0)
##  stringi         1.1.5   2017-04-07 cran (@1.1.5) 
##  stringr         1.2.0   2017-02-18 cran (@1.2.0) 
##  withr           1.0.2   2016-06-20 CRAN (R 3.4.0)
</code></pre>
<h3>Want more?</h3>
<p>Check other <a target="_blank" rel="nofollow" href="https://twitter.com/jhubiostat">@jhubiostat</a> student and alumni blogs at <a target="_blank" rel="nofollow" href="http://bmorebiostat.com/">Bmore Biostats</a> as well as topics on <a target="_blank" rel="nofollow" href="https://twitter.com/search?q=%23rstats">#rstats</a>.</p>
<p><img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/FellgernonBit-rstats/~4/mw-GRpriOZM"></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://feedproxy.google.com/~r/FellgernonBit-rstats/~3/mw-GRpriOZM/Updating-R"> Fellgernon Bit - rstats</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/sAJA_FjLMCE"></a></div>