什么是`.__ devtools __。`r软件包名称空间中的环境是什么?

发布于 2025-02-07 13:10:53 字数 782 浏览 1 评论 0 原文

在阅读R软件包的源代码时,辅助帮助者可以使用软件包名称空间,但我注意到它们有时会引用 .__ DevTools __。环境。但是我从未在野外的任何包装名称空间中遇到过这个环境,也无法成功找到有关的任何信息。

我确实了解其他环境。我的第一个猜测是,这与{devtools}软件包有关,但即使该软件包在其名称空间中也没有这个环境。

get_env_from_ns <- function(x) {
  ns <- .getNamespace(x)
  
  c(
    rlang::env_has(ns, ".__NAMESPACE__."),
    rlang::env_has(ns, ".__S3MethodsTable__."),
    rlang::env_has(ns, ".__DEVTOOLS__.")
  )
}

library(devtools)
#> Loading required package: usethis
get_env_from_ns("devtools")
#>      .__NAMESPACE__. .__S3MethodsTable__.       .__DEVTOOLS__. 
#>                 TRUE                 TRUE                FALSE

创建我有两个问题:

  • 这个环境是什么?
  • 是否有一个使用此环境的软件包的示例?

While reading source code of R packages that supple helpers to work with package namespaces, I have noticed that they sometimes refer to a .__DEVTOOLS__. environment. But I have never encountered this environment in any package namespace in the wild, nor can I successfully find any information about.

I do understand what other environments are. My first guess would have been that this is related to the {devtools} package, but even that package doesn't have this environment in its namespace.

get_env_from_ns <- function(x) {
  ns <- .getNamespace(x)
  
  c(
    rlang::env_has(ns, ".__NAMESPACE__."),
    rlang::env_has(ns, ".__S3MethodsTable__."),
    rlang::env_has(ns, ".__DEVTOOLS__.")
  )
}

library(devtools)
#> Loading required package: usethis
get_env_from_ns("devtools")
#>      .__NAMESPACE__. .__S3MethodsTable__.       .__DEVTOOLS__. 
#>                 TRUE                 TRUE                FALSE

Created on 2022-06-15 by the reprex package (v2.0.1)

So I had two questions:

  • What is this environment?
  • Is there an example of a package that uses this environment?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹊巢 2025-02-14 13:10:53

.__ DevTools __。是由 devtools 软件包创建的环境的名称。如果您在`您会发现它说

load_all加载的软件包现在将DevTools元数据存储在其名称空间环境中,以称为 .__ DevTools __。的变量,可以使用dev_meta函数访问。 (Winston Chang。修复#128)

它出现在A 。看来,该软件包不再使用此环境来跟踪元数据,因此该功能似乎是写入较旧版本的软件包。

.__DEVTOOLS__. was the name of an environment created by the devtools package. If you search for that in the `devtools package NEWS you'll find that it says

Packages loaded with load_all now store devtools metadata in their namespace environment, in a variable called .__DEVTOOLS__. This can be accessed with the dev_meta function. (Winston Chang. Fixes #128)

It appeared in a the metatdata.R file. It appears that this environment is no longer used by the package to track metadata so the function seems to be written to work with an older version of the package.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文