Question

How can I find the absolute path of the personal R package library for a certain user on a Unix system (including Linux, OSX, Solaris)? To get the home path of the current user, we can use:

path.expand(Sys.getenv("R_LIBS_USER"))

However, I would like to lookup the path for another user, given that the current user has sufficient privileges to do so. It should work, even if the user directories are not in the default /home.

Was it helpful?

Solution

Based on Mark's suggestions, the best I've come up with is:

userlib <- function(username){
  userlib <- path.expand(sub("~", paste0("~", username), Sys.getenv("R_LIBS_USER"), fixed=TRUE));
  if(file.exists(userlib)){
    return(userlib)
  } else {
    return("")
  }
}

This seems to give what I need, at least on Linux and OSX.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top