Recently, I was writing a shell script to automate the installation of some bioinformatics tools on a particular platform. One of the tools depended on the R package “VGAM”. Installing packages manually is trivial—you simply fire up R, type
install.packages("YourPackageName"), select your closest mirror, and then BAM! you’re done.
I’ve used the shebang-able Rscript before to run R one-liners on the command line (try
Rscript -e 'rnorm(5)' on your prompt), so I figured batch installation of packages would be just as simple, right? Well, yes and no. If you try to just run the
install.packages function as is using
Rscript, the command will fail since no mirror is specified.
[standage@lappy ~] Rscript -e 'install.packages("VGAM")' Error in contrib.url(repos, type) : trying to use CRAN without setting a mirror Calls: install.packages -> .install.macbinary -> contrib.url Execution halted
A bit of Google searching provided a couple of solutions to this problem: either use the
# Use the getCRANmirrors() function for a list of all possible mirrors chooseCRANmirror(76) install.packages("VGAM")
…or simply pass the mirror URL as the
I ended up going with the second one, and it worked beautifully!