[R-pkg-devel] Does a file in tests/ know which package it is being run from?

Dirk Eddelbuettel edd @end|ng |rom deb|@n@org
Sat Apr 17 01:05:51 CEST 2021


When a script in tests/ is being run by R CMD check and friends, can we know
what package it is currently being part of?  I want to access some package
files via system.file(..., package=pkg) which works just fine, but it feels
redundant to assign the package name to the pkg variable.  

Case in point is that I once again forgot to update the inst/NEWS.Rd file for
an upload today.  As I use a structured format, I can fairly reliably extract
the most recent version therein, and DESCRIPTION has the current version. So
what follows works fine , but per the preceding paragraph, do I need really
need 'pkg <- "RcppAPT"' here or can I do better?

Thanks for any pointers,  Dirk

---- tests/version.R for RcppAPT follows  -----------------------------------
pkg <- "RcppAPT"
nrdfile <- system.file("NEWS.Rd", package = pkg)
if (file.exists(nrdfile)) {
    nrd <- readLines(nrdfile)
    ver <- as.package_version(gsub(".* ([0-9\\.]+) .*", "\\1", nrd[grepl("\\{Changes", nrd)]))
    dcf <- read.dcf(system.file("DESCRIPTION", package = pkg))
    cur <- as.package_version(dcf[[1,"Version"]])
    if (cur != ver[1]) stop("Expected NEWS entry for ", cur, " but saw ", ver[1], call. = FALSE)
}
-----------------------------------------------------------------------------


-- 
https://dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org



More information about the R-package-devel mailing list