Is there any path code in the R package that can determine which package or namespace it belongs to?
Reference Information. I find that I have common code between packages that just differs from the package name. One common example: tests/testthat.R :
library(testthat) library(ShiftedExcitation) test_check("ShiftedExcitation")
If the code can find out which package or namespace it belongs to, I could avoid a number of places where the package name is now indicated.
Now I am defining a hidden variable containing the package name, say
.PKG <- "ShiftedExcitation"
and then use something along the lines *
library(testthat) library(.PKG, character.only = TRUE) test_check(.PKG)
but I'm curious if there is a more elegant solution.
* I did not get this while testthat.R is evaluated outside the package namespace. However, it works to define the unittest function inside the package code.
source share