I wrote a package to cite other R packages. I use dummy packages created with usethis::create_package() for testing.
I'd like to use getNamespaceVersion() (rather than packageVersion()) to get package versions because it's faster, returns a character vector by default and is a bit cleaner in my opinion. The problem is that getNamespaceVersion() requires to have package metadata files to work, which is not the case of the fake packages I use.
local({
local_pkg <- function(Package, ..., env = parent.frame()) {
dir <- withr::local_tempdir(.local_envir = env)
withr::local_libpaths(dir, action = "prefix", .local_envir = env)
pkg_path <- file.path(dir, Package)
usethis::ui_silence(
usethis::create_package(
path = pkg_path,
fields = list(Type = "Package", Package = Package, ...),
rstudio = FALSE,
open = FALSE
)
)
}
local_pkg(
"foo",
Title = "Bar",
`Authors@R` = utils::person("X", "Y", role = "aut"),
Version = "1.0.0",
Date = "2020-01-01"
)
getNamespaceVersion("foo")
})
#> <NA>
#> NA
#> Warning message:
#> In loadNamespace(name) : package ‘foo’ has no 'package.rds' in Meta/
Is there an easy and efficient way to create or emulate the files needed to make getNamespaceVersion() work with such temporary packages?