Вопрос

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