if (rlang::is_installed("testthat")) {
library(testthat)
mytool <- function() {
deprecate_soft("1.0.0", "mytool()")
10 * 10
}
# Forcing the verbosity level is useful for unit testing. You can
# force errors to test that the function is indeed deprecated:
test_that("mytool is deprecated", {
rlang::local_options(lifecycle_verbosity = "error")
expect_error(mytool(), class = "defunctError")
})
# Or you can enforce silence to safely test that the function
# still works:
test_that("mytool still works", {
rlang::local_options(lifecycle_verbosity = "quiet")
expect_equal(mytool(), 100)
})
}
Run the code above in your browser using DataLab