Transferring Packages to New R Installation (Mac OSX)

These instructions are for Mac OSX, but can be adapted to work on Windows.

You have installed a new R version from the CRAN website ( and find out that the packages you previously installed are no longer available. It would be quite time consuming to reinstall all the packages. How to proceed?

1: Open the previous version of R.

The easiest way to do this is to download the RSwitch program from

Install the program and drag the icon to the applications folder (the first time you open the file, you will need to approve it).

The RSwitch program instantaneously switches between R versions. When you open the RSwitch program, it shows the installed versions of R. You can click on the version you want to make active.

You will need to access R from TERMINAL (not from the R.App icon).

Open terminal and enter:

ls -l /Library/Frameworks/R.framework/Versions/

This should give you all the installed versions (as seen in RSwith) and the current version.

If you click on the previous version (i.e. 3.3) in RSwitch and enter in terminal:

ls -l /Library/Frameworks/R.framework/Versions/

you should have the previous version (i.e. 3.3) as the current R version.

Now enter


in terminal and the old version (i.e. 3.3) of R should start up.


2: Save the installed packages from your previous R version

With the previous version of R active in the console, create a file on the desktop that contains the names of old the packages:

temp <- installed.packages()

installed <- as.vector(temp[[,”Priority”]), 1])

save(installed, file=”~/Desktop/installed.rda”)

You should now have a file on the desktop called


 you can also use this method to copy installed packages to another computer; you will have to copy the installed.rda file to the desktop of your other computer.


3: Open the new version of R

Close the terminal to quit R  and then re-open terminal (without R running).

In RSwitch, select the new version of R (i.e. 3.4)

In terminal enter


and the new version of R should open (i.e. 3.4).


4: Restore the packages

With the new version of R open in terminal, the packages can be restored by: