Jessica Kate Rowntree Ward

Updating R as pain free as possible

Last week I had to do update R on my work computer, it turned into a rather painful task which took me the best part of the day and resulted in me wanting to rage-quit several times!

I was the panda

I was naive and didn't think about my packages and because I was doing a major update (going from version 3.4.something to 3.5.1) I needed to re-install all of my packages but I had no complete list of the packages that I had been using.

Only after I had gone through this pain did someone tell me about the `installR` package which probably could have saved me a whole heap of time! A couple of days later whilst at home I made the time to install the update on my laptop, I then discovered that the `installR` package is not available for MacOS :(

I did however find a relatively straightforward solution which I am documenting here in case future me needs to use this method again. I'm sure there are much better ways of doing this but this one worked for me.

I used the `updateR` package which I came across thanks to this blog post

The updateR package is great but it is still in development and there seem to be some bugs with the `needed packages` function - which was kinda the whole reason for using this package in the first place so I modified my workflow slightly

  1. 1. First I generated a snapshot of the packages that I had installed using `pacs <- installed.packages()` and converted the output to a data frame
  2. 2. Then I printed the first coolumn (containing the names of the packages) copied the output to a script file and used the wonderful `Alt` + `highlight` that allows you to edit multiple lines in Rstudio to manipulate the list into the format that I wanted
  3. 3. Once I had a saved list of package names (packagename, packagename, packagename...) I was ready to update my R version following the steps in this tutorial
  4. 4. Then I installed the librarian package
  5. 5. Then using the librarian package and the previously saved list of package names to re install all of the packages that I need
  6. 6. librarian::shelf(packagename,packagename,packagename) MAGIC

This works for all CRAN packages but it failed for github packages because the syntax of librarian::shelf requires that the github username prefixes the package name, fortunately when librarian failed to load these packages it listed the names of all of them in the error message so it was easy for me to manually reinstall them.