Installing all CRAN packages that are not already installed?

Better if you use:

    check.and.install.Package<-function(package_name){
        if(!package_name%in%installed.packages()){
           install.packages(package_name)
        }
     }

call the function and check if required package is installed:

    check.and.install.Package("pkgName")

type this command and then all packages will be installed automatically:

install.packages(available.packages()[,1])

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?!?


1) Why would you want to do that? There are over 3500 (as of Feb 2012) 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.

Tags:

R

Cran