Home > Back-end >  What is `.__DEVTOOLS__.` environment in R package namespace?
What is `.__DEVTOOLS__.` environment in R package namespace?

Time:06-15

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?

CodePudding user response:

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

  • Related