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

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Mon Jun 17 15:05:56 CEST 2024


I am not going to search the sources for it (your problem, your work ;-) ), but the wording would be consistent with a call like

.libPaths(c(Sys.getenv("R_LIBS"), Sys.getenv("R_LIBS_USER")))

-pd

> On 17 Jun 2024, at 13:40 , Iago Giné Vázquez <iago.gine using sjd.es> wrote:
> 
> Thanks,
> 
> Regarding .libPaths, I am asking for the call to `.libPaths()`, so I understand there is no `new` in the call, as in the documentation I cited.
> 
> Iago
> 
> De: peter dalgaard <pdalgd using gmail.com>
> Enviat el: dilluns, 17 de juny de 2024 13:26
> Per a: Iago Giné Vázquez <iago.gine using sjd.es>
> A/c: r-help using r-project.org <r-help using r-project.org>
> Tema: Re: [R] Help trying to understand R documentation on libraries paths
>  
> (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

-- 
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