tags:

views:

443

answers:

2

The following R commands will install all CRAN packages:

availablePackages <- available.packages()[,1]
install.packages(availablePackages)

And the following command will list all installed packages:

installedPackages <- .packages(all.available = TRUE)

My question is: How do I instruct R to install all CRAN packages that are not already installed?

+6  A: 

1) Why would you want to do that? There are over two thousand of them?

2) Did you look at CRAN Task Views and the ctv package that allows you to install packages from a given task?

3) You bold-face question is a simple indexing query you can do by hand (and besides that, also see help(sets))

R> available <- LETTERS                  # a simple set
R> installed <- LETTERS[c(1:10, 15:26)]  # a simple subset
R> available[ ! available %in% installed ]
[1] "K" "L" "M" "N"
R> 

Edit: in response to your follow-up:

a) If a package does not pass 'R CMD check' on Linux and Windows, it does not get uploaded to CRAN. So that job is done.

b) Getting all depends at your end is work too as you will see. We did it for cran2deb which is at http://debian.cran.r-project.org (which does full-blown Debian package building which is more than just installing). We get about 2050 out of 2150 packages built. There are a few we refuse to build because of license, a few we cannot because of missing headers or libs and a few we cannot build because they need e.g. BioConductor packages.

Dirk Eddelbuettel
I want to make sure my system has all the right dependencies, and I'm testing that by trying to build the entire CRAN :-) Does CRAN contain many broken packages that I should expect won't build?
knorv
There are a few that you should expect won't build if you don't have libraries installed in standard places. rgdal for example assumes GDAL is installed somewhere it's configure script can find. If you have it installed in a non-standard location, you will have to manually point R CMD INSTALL to the right place.
Sharpie
+1  A: 

Frankly, I think it's painstaking job... it would last for days, even weeks (depending on resources), but here's the code (I just enjoy doing trivial things):

# get names of installed packages
packs <- installed.packages()
exc <- names(packs[,'Package'])

# get available package names
av <- names(available.packages()[,1])

# create loooong string
ins <- av[!av %in% exc]
install.packages(ins)

I still don't get why you're doing this, but, hey... some things are just not meant to be.... What wonders me the most is the fact that you've already answered your own question! You got what you needed, and it's just up to you to put things together... Are we missing the point? Did you have something else in mind?!?

aL3xa