1

Actual question

How can I query the default location of a personal package library/libraries as described in the R Installation and Adminstration even after environment variables like R_LIBS_USER or .libPaths() etc. might already have been changed by the user?

I'd just like to understand how exactly R determines the default settings in a platform-independent way.

Naively, I was hoping for something equivalent to R.home("library"), e.g. R.user("library")

Due dilligence

I checked this post and the answers sort contain the information/paths I'd like to retrieve. Unfortunately I only really know my way around on Windows, not on OS X or Linux. So I'm not sure if/how much of this is correct in a generic sense (home directory, separation of user vs. system-wide stuff etc.):

OS X

/Library/Frameworks/R.framework/Resources/library

Linux

/usr/local/lib/R/site-library
/usr/lib/R/site-library
/usr/lib/R/library

I also looked into the manual, but that only gave me a basic idea of how R handles these sort of things (maybe just looked in the wrong corner, any pointers greatly appreciated).

Background

I sometimes create a temporary, fresh package library for the purpose of having a "sandbox" for systematic testing (e.g. when planning to upgrade certain package dependencies) .

When I'm done, I'd like to delete that library again while making absolutely sure that I don't accidentally delete one of the standard libraries (personal library/libraries and system-wide library).

I'm starting to put together a little package called libr for these purposes. Function deleteLibrary contains my current approach (lines 76 ff.):

  ## Personal libs //
  r_vsn <- paste(R.version$major, gsub("\\..*", "", R.version$minor), sep = ".")
  if (.Platform$pkgType == "win.binary") {
    lib_p <- file.path(Sys.getenv("HOME"), "R/library", r_vsn)
  } else if (.Platform$OS.type == "mac.binary") {
    lib_p <- file.path(Sys.getenv("HOME"), "lib/R", r_vsn)
    ## Taken from https://stackoverflow.com/questions/2615128/where-does-r-store-packages
    ## --> Hopefully results in something like: '/Users/{username}/lib/R/{version}'
  } else if (.Platform$OS.type == "source" && .Platform$OS.type == "unix") {
    lib_p <- file.path(Sys.getenv("HOME"), 
      c(
        "local/lib/R/site-library", 
        "lib/R/site-library",
        "lib/R/library"
      ), r_vsn)

    ## Taken from https://stackoverflow.com/questions/2615128/where-does-r-store-packages
    ## --> Hopefully results in something like: 
    ##     '/usr/local/lib/R/site-library/{version}'
    ##     '/usr/lib/R/site-library/{version}'
    ##     '/usr/lib/R/library/{version}'
  } else {
    stop("Don't know what to do for this OS type")
  }
Community
  • 1
  • 1
Rappster
  • 12,762
  • 7
  • 71
  • 120

0 Answers0