문제

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