[R] Specify CRAN repository from command line

Dirk Eddelbuettel edd at debian.org
Mon Jul 27 05:33:43 CEST 2009


On 27 July 2009 at 14:55, Aaron Hicks wrote:
| It feels like I should be able to do something like:
| 
| R CMD INSTALL lib='/usr/lib64/R/library' repos='http://proxy.url/cran' package

Here's what I do using littler, you can substitute Rscript as well:

    #!/usr/bin/env r
    #
    # a simple example to install one or more packages
    
    if (is.null(argv) | length(argv)<1) {
    
      cat("Usage: installr.r pkg1 [pkg2 pkg3 ...]\n")
      q()
    
    }
    
    ## adjust as necessary, see help('download.packages')
    repos <- "http://cran.us.r-project.org"
    
    ## this makes sense on Debian where no packages touch /usr/local
    lib.loc <- "/usr/local/lib/R/site-library"

    install.packages(argv, lib.loc, repos, dependencies=TRUE)

That way, I just say 'install.r foo bar baz' and these packages, plus their
Depends:, will get installed.

[ That said, I actually don't do that anymore because we now have cran2deb so
I can just say 'apt-get install r-cran-foo r-cran-bar r-cran-baz' but that is
a special case for Debian and pretty recent as per the announcement a few
days ago. ]

| We have a bunch of servers (compute nodes in a Rocks cluster) in an isolated subnet, there is a basic pass-through proxy set up on the firewall (the head node) which just passes HTTP requests through to our nearest CRAN mirror.
| 
| when using install. packages it's easy to make R install from the repository with the repos='address' option, but I can't figure out how do this from the command line.
| 
| Is there a command line option for this? Currently I'm doing it using an R script, but that's causing issues because it's not 'visible' to the installer.
| 
| This would greatly streamline R installation with a standard package set.

The repos argument can otherwise be set in ~/.Rprofile or Rprofile.site.

Dirk

-- 
Three out of two people have difficulties with fractions.




More information about the R-help mailing list