[R-sig-Debian] installing packages systemwide

Dirk Eddelbuettel edd at debian.org
Fri Aug 19 20:10:26 CEST 2011


(Removed r-help, keeping it on r-sig-debian only)

On 19 August 2011 at 13:10, Mary Kindall wrote:
| I installed some downloaded packages in R. I always do
| $sudo R CMD INSTALL <anRpackage.tar.gz>
| 
| 
| By default it is storing these packages into my directory
| /home/mary/R/x86_64-pc-linux-gnu-library/2.13/.
| 
| However I want them to be systemwide into /usr/local/lib/R/site-library/
| folder.
| 
| I tried
| $sudo R
| R> install.packages("anRpackage", dep=TRUE)
| 
| I did not succeed into getting them install in req folder.
| Any idea?

Yes, this is my preference too, and it can be achieved in a number of
ways. Here is what I do:

 1. Write-permission -- I have set up the Debian / Ubuntu package to create
    the top-level directory witrh group 'staff' and group-wide mode:

    $ ls -dl /usr/local/lib/R/site-library/
    drwxrwsr-x 2 root staff 4096 2011-03-11 09:51 /usr/local/lib/R/site-library/
 
    So you have to add yourself to the 'staff' group (which always exists),
    or another suitable group, and/or take other equivalent measures. If you
    can write there, you do not even need 'sudo'. That is a good thing.

 2. Select the target directory explicitly, so a local R function helps, or
    in my case a local adaption of the script 'install.r' from the littler package:

    $ cat ~/bin/install.r
    #!/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"
    repos <- "http://cran.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)



    The main key here is that the source repo and the target directory are
    hardwired, and then I can just say

    $ ~/bin/install.r foo bar biz

    and those three packages get installed to /usr/local/lib/R/site-library

Hope this helps,  Dirk

-- 
Two new Rcpp master classes for R and C++ integration scheduled for 
New York (Sep 24) and San Francisco (Oct 8), more details are at
http://dirk.eddelbuettel.com/blog/2011/08/04#rcpp_classes_2011-09_and_2011-10
http://www.revolutionanalytics.com/products/training/public/rcpp-master-class.php



More information about the R-SIG-Debian mailing list