How do I check and compare multiple versions of R functions for a package?
I use unit tests through testthat
for many of my simpler functions in R, but I have more complex functions that combine simple functions and business logic. I would like to test the cumulative impact through the before and after view for a sample of input data. Ideally I would like to do this for various candidate changes.
At the moment I:
- Using Rmarkdown Documents
- Downloading the package as is
- Getting my sample
- Running my sample through the as-is package and outputting the results table
-
source
new copies of functions - Running my sample again and outputting the results table
- Reload the package and
source
execute different copies of functions as needed
This proved to be difficult due to some functions that are in the package namespace still executing versions of the function packages, which makes the results unreliable unless I completely reload all dependent functions downstream. In addition, the mechanism is complex to manage and difficult to reuse.
Is there a better strategy for testing candidate changes in R packages?
source to share
I mitigated this issue by creating a subpackage in my impact analysis folder that contains the changed functionality.
Then I use devtools::load_all
to download these new versions of the functions.
I can then compare and contrast the results by referring to the originals through a namespace, eg. myoriginalpackage:::testfunction
looking for new ones withtestfunction
source to share