[R] Help trying to understand R documentation on libraries paths

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Mon Jun 17 13:26:10 CEST 2024


(Inline)

> On 17 Jun 2024, at 09:51 , Iago Giné Vázquez <iago.gine using sjd.es> wrote:
> 
> Hi,
> 
> 1 - On help(".libPaths", help_type = "text") one can read:
> 
> First, '.Library.site' is initialized from 'R_LIBS_SITE'.
> 
> However, I have
> 
>> Sys.getenv("R_LIBS_SITE")
> [1] "c:/Users/i.gine/AppData/Local/Programs/R/R-4.4.1/site-library"
>> .Library.site
> character(0)
> 
> Is this consistent?

It is implied that R_LIBS_SITE should point to an existing directory. I see the same thing on Mac:

> .Library.site
character(0)
> Sys.getenv("R_LIBS_SITE")
[1] "/Library/Frameworks/R.framework/Resources/site-library"
> list.files(Sys.getenv("R_LIBS_SITE"))
character(0)

I.e., R_LIBS_SITE is where a site library _if any_ should live. If it is not there, there is no poin in searching it. Unless you actually have a site-library, I don't think there is a problem.

> 
> 2 - Next, on the same help document, one can read:
> 
> Then, '.libPaths()' is called with the combination
>     of the directories given by 'R_LIBS' and 'R_LIBS_USER'.
> 
> 
> This time, I get
>> Sys.getenv("R_LIBS")
> [1] ""
>> Sys.getenv("R_LIBS_USER")
> [1] "c:/Users/i.gine/AppData/Local/Programs/R/R-4.4.0/library"
>> .libPaths()
> [1] "C:/Users/i.gine/AppData/Local/Programs/R/R-4.4.0/library" "C:/Users/i.gine/AppData/Local/Programs/R/R-4.4.1/library"
> 
> 
> Later is written:
> 
> Function '.libPaths' always uses the values of '.Library' and
>     '.Library.site' in the base namespace.
> 
> and indeed
> 
>> .Library
> [1] "c:/Users/i.gine/AppData/Local/Programs/R/R-4.4.1/library"
> 
> 
> Then, shouldn't be this specified above together with "directories given by 'R_LIBS' and 'R_LIBS_USER'"?
> 

The logic of .libPath() is 

> .libPaths
function (new, include.site = TRUE) 
{
    if (!missing(new)) {
        new <- Sys.glob(path.expand(new))
        paths <- c(new, if (include.site) .Library.site, .Library)
        paths <- paths[dir.exists(paths)]
        .lib.loc <<- unique(normalizePath(paths, "/"))
    }
    else .lib.loc
}

so if you "call it with" new=something, then (.Library.site, .Library) is automagically appended, unless you expressly tell it not to. 

-pd

> 
> Am I understanding it wrongly? Otherwise, what do you think on the current way this help page is explained?
> 
> Thank you for your help and time.
> 
> Best regards,
> 
> Iago
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-help mailing list