Updating R Packages Automatically

Here’s a very naive program I just wrote to update all of the R packages I have on my system after I update the core R binary. Please let me know if there’s anything obviously wrong with this, such as failing to update items with chains of dependencies.

1
2
3
4
5
6
7
8
9
10
11
12
13
all.packages <- installed.packages()
r.version <- paste(version[['major']], '.', version[['minor']], sep = '')
 
for (i in 1:nrow(all.packages))
{
    package.name <- all.packages[i, 1]
    package.version <- all.packages[i, 3]
    if (package.version != r.version)
    {
        print(paste('Installing', package.name))
        install.packages(package.name)
    }
}

2 responses to “Updating R Packages Automatically”

  1. Bryan

    Why not just use update.packages() ?