>>>>> Pavel Krivitsky via R-devel
>>>>> on Thu, 12 Nov 2026 03:40:42 +0000 writes:
> Dear All,
> Does anyone know if this is an omission or if there is a reason for doing
it in this way that I am not seeing? These element names seem to be an artefact
of how the information was extracted:
> ```
> getNamespaceName("stats")
> #> name
> #> "stats"
> getNamespaceVersion("stats")
> #> version
> #> "4.7.0"
> ```
> This is in contrast to `packageVersion()`, which reads it from the
`DESCRIPTION` file but returns an unnamed vector, which leads to unexpected
behaviour:
> ```
> as.package_version(getNamespaceVersion("stats")) ==
packageVersion("stats")
> #> [1] TRUE
> identical(as.package_version(getNamespaceVersion("stats")),
packageVersion("stats"))
> #> [1] FALSE
> identical(as.package_version(unname(getNamespaceVersion("stats"))),
packageVersion("stats"))
> #> [1] TRUE
> ```
> The attached patch uses `[[]]` rather than `[]` to extract
> namespace name and version, which removes the names. It
> doesn't seem to break anything, but, again, there may be
> another reason.
Thank you, Pavel,
I believe it is a very valid question, and I see that these,
(single bracket) [-indexing for the getNamespaceVersion() and
getNamespaceName() utilities have been there from the very
beginning when Luke Tierney added namespace support for most
packages, svn log showing
----------------------------------------------------------
r23392 | luke | 2003-02-27 19:02:45 +0100
Added name space support for packages that do not use methods.
----------------------------------------------------------
Indeed, the "counterpart" functionality for packages, provided
via packageDescription() has been using [[-indexing on
purpose, for these.
I'm guessing that these two functions just being simple
convenience accessors, Luke Tierney rather emphasized on all
the other implications and improved semantic namespaces brought
to R, (and `[..]` has been more "natural" and less typing...).
I even vaguely remember that in these early years of R, most R
users and developers were unaware of the fine distinction of `[`
and `[[` for _atomic_ vectors ... at least I think I myself was
(not much paying attention to it).
Consequently, I do think your proposed mini-patch makes sense
really, and should be applied.
I'll do this in my "working version" of R-devel for now,
preparing to commit unless I see bad effects or we get
opposition to such a change here.
Martin
> Best Regards,
> Pavel
> Index: src/library/base/R/namespace.R
> ===================================================================
> --- src/library/base/R/namespace.R (revision 90876)
> +++ src/library/base/R/namespace.R (working copy)
> @@ -51,7 +51,7 @@
> getNamespaceName <- function(ns) {
> ns <- asNamespace(ns)
> if (isBaseNamespace(ns)) "base"
> - else .getNamespaceInfo(ns, "spec")["name"]
> + else .getNamespaceInfo(ns, "spec")[["name"]]
> }
> getNamespaceVersion <- function(ns) {
> @@ -58,7 +58,7 @@
> ns <- asNamespace(ns)
> if (isBaseNamespace(ns))
> c(version = paste(R.version$major, R.version$minor, sep = "."))
> - else .getNamespaceInfo(ns, "spec")["version"]
> + else .getNamespaceInfo(ns, "spec")[["version"]]
> }
> getNamespaceExports <- function(ns) {
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel