Michael Chirico
2023-Jan-09 20:25 UTC
[Rd] Shouldn't "Loading" be "Attaching" when referring to library() calls?
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?
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.
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
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
Martin Maechler
2023-Jan-10 09:26 UTC
[Rd] Shouldn't "Loading" be "Attaching" when referring to library() calls?
>>>>> 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
Seemingly Similar Threads
- Shouldn't "Loading" be "Attaching" when referring to library() calls?
- Clang 5, UBsan, runtime error: addition of unsigned offset to X overflowed to Y
- Allowed operations for passes that report "no change"
- isNamespaceLoaded() while the namespace is loading
- [LLVMdev] sparc assembly code generation with 2.9/final clang and llvm