[Rd] Shouldn't "Loading" be "Attaching" when referring to library() calls?

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Tue Jan 10 10:26:53 CET 2023


>>>>> Michael Chirico via R-devel 
>>>>>     on Mon, 9 Jan 2023 12:25:46 -0800 writes:

    > require() and library() both emit this message immediately before
    > running library():

    > "Loading required package: %s"

    > https://github.com/r-devel/r-svn/blob/4198a2941b702d965bb2374c2b908f48c369f40a/src/library/base/R/library.R#L967-L968

    > https://github.com/r-devel/r-svn/blob/4198a2941b702d965bb2374c2b908f48c369f40a/src/library/base/R/library.R#L684-L685

    > Shouldn't "Loading" be "Attaching" instead?

Good question... I had asked myself as well a couple of times.

The vagueness is mostly "historical" in the sense that
originally R (nor S) had namespaces.
OTOH,  attach(.)  has always worked for data frames (already in pre-R S).

Still, I agree (when teaching and otherwise), we should
clearly distinguish the two notably in the context of packages
and their namespaces.


    > My understanding is "a package is loaded" is equivalent to
    > "isNamespaceLoaded()", i.e., loadNamespace() was run. And that "a
    > package is attached" is equivalent to "pkg %in% .packages()", i.e.,
    > library(pkg) was run.

or (easier for teaching)  that  "package:<pkg>" %in% search()
-- which is what .packages() does {by default}.

I agree with the above.


    > Is the terminology not so precise?

    > There's certainly ambiguity in the internal variable names referenced
    > above -- in require, we see

    > loaded <- paste0("package:", package) %in% search()
    > https://github.com/r-devel/r-svn/blob/4198a2941b702d965bb2374c2b908f48c369f40a/src/library/base/R/library.R#L680

again, historical:  require() exists for considerably longer
than namespaces.

I think we should at least change the message printed by
require() and library() you mentioned above.

Martin


    > Whereas in library() [via .getRequiredPackages2()] we see

    > attached <- paste0("package:", pkg) %in% search()
    > https://github.com/r-devel/r-svn/blob/4198a2941b702d965bb2374c2b908f48c369f40a/src/library/base/R/library.R#L931

    > Mike C



More information about the R-devel mailing list