I'm working on a package in which a function was written by an expert who has since left the project. I myself am not an expert and thus want to make sure that I never break the original algorithm without noticing.
Thus, I'd like to test the output of the current version of a function in my package against that of the same function in a previous version of the package, identifiable by a git commit, branch, or similar in the package repository.
Lets say, for example, I would like to compare the output of foo()
from the dev
branch against foo()
from a certain commit on the main
branch.
test_that("old foo matches new foo", {
foo_new <- foo()
foo_old <- ... # install and load earlier version of foo somehow
expect_equal(foo_old("bar"), foo_new("bar"))
})
Can I somehow install the old version of the package temporarily to run the test and how can I avoid messing up the namespace?