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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top