Tuesday 11 December 2012

Loading all installed R packages

The other day I was trying to set up an R for Windows installation on a USB drive. As I don't have a Windows machine, I had to use the university computer to do this task. However, for some reason, they've blocked R from downloading and installing packages using the install.packages() command. This required that I download the zip files and manually install them. No problem with that, until packages require the installation of dependencies. To ensure that I got all the packages I needed, I wanted a function that would load all of the packages locally installed on my machine. To my surprise, I didn't find a straight-forward solution, so I came up with the following kludge:
lapply(.packages(all.available = TRUE), function(xx) library(xx,     character.only = TRUE))
There may be a more elegant way to do the above, but it worked. Elegance is occasionally overrated.

6 comments:

Unknown said...
This comment has been removed by the author.
Unknown said...

Have a look at "installed.packages()"

cellocgw said...

What problem are you trying to solve? Typically, assuming you've installed the dependencies, the 'library' command will automatically grab dependencies.

Kirsty F. McGregor said...

Sam sounds like an I.T department security thing? You can ask them to let you do this on the uni computer if it's causing you problems... But seems like you got around it! K

J.A. González said...

Perfect if you previously assign the list to a variable (L) and then:

unique(unlist(L))

Unknown said...

Sir, You have saved me from an extensive n painful search through my packages for defunct packages.Thank you.