Where are located the packages and who is the owner

I have done a function list.packages() in my package HelpersMG.

.libPaths() returns the list of locations for packages... but who is where ?:

structure(lapply(.libPaths(), FUN = function(path) {list.dirs(path=path, full.names = FALSE, recursive = FALSE)}), .Names=.libPaths())

To get the owner for each location:

structure(as.list(system(paste("ls -ld ", .libPaths()," | awk '{print $3}'", collapse=";"), intern=TRUE)), .Names=.libPaths())

It works both in ubuntu and MacOSx. I don't have Windows computer to do the same.

The path used by .libPaths() are defined in one of the files used for R configuration at startup:
in ubuntu: /usr/lib/R/etc/Renviron
in MacosX: /Library/Frameworks/R.framework/Resources/etc/Renviron
> file.path(Sys.getenv("R_HOME"), "etc", "Renviron")
[1] "/Library/Frameworks/R.framework/Resources/etc/Renviron"
and 
~/.Renviron
~/.Rprofile

The files /usr/lib/R/etc/Renviron and ~/.Renviron are read in shell and ~/.Rprofile is a R file.
sudo must be used to modify the /usr/lib/R/etc/Renviron file.

In the file /usr/lib/R/etc/Renviron, you can find these lines (or similar):
R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.4'}
#R_LIBS_USER=${R_LIBS_USER-'~/Library/R/3.4/library'}

# edd Apr 2003  Allow local install in /usr/local, also add a directory for
#               Debian packaged CRAN packages, and finally the default dir
# edd Jul 2007  Now use R_LIBS_SITE, not R_LIBS
R_LIBS_SITE=${R_LIBS_SITE-'/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library'}

This is where the system variables are initially set. They can be changed in ~/.Renviron; for example:
> cat ~/.Renviron
R_LIBS_USER=""

You can read them from within R using:
> Sys.getenv(c("R_LIBS_SITE", "R_LIBS_USER"))
                                                               R_LIBS_SITE 
"/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library" 
                                                               R_LIBS_USER 
                                     "~/R/x86_64-pc-linux-gnu-library/3.4" 


Commentaires

Posts les plus consultés de ce blog

Standard error from Hessian Matrix... what can be done when problem occurs

stepAIC from package MASS with AICc

Install treemix in ubuntu 20.04