generated from pharmaverse/admiraltemplate
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #466 inform function skeleton and tests
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' Deprecation with Soft Message | ||
#' | ||
#' Wrapper around `lifecycle::deprecate_soft()` | ||
#' | ||
#' @param ... | ||
#' | ||
#' @return Return value of the expression | ||
#' | ||
#' @keywords messages | ||
#' @family messages | ||
#' | ||
#' @details | ||
#' | ||
#' @export | ||
deprecate_inform <- function(...) { | ||
tryCatch( | ||
lifecycle::deprecate_soft(...), | ||
warning = \(w) { | ||
message(conditionMessage(w)) | ||
tryInvokeRestart("muffleWarning") | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# lifecycle_admiral Test 1: Message is sent to user | ||
|
||
Code | ||
example_fun(data) | ||
|
||
# lifecycle_admiral Test 2: Nicer message is sent to user | ||
|
||
Code | ||
example_fun(data) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## Test 1: Message is sent to user ---- | ||
test_that("lifecycle_admiral Test 1: Message is sent to user", { | ||
example_fun <- function(dataset) { | ||
deprecate_inform("1.0.0", "example_fun()", "example_fun2()") | ||
assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID)) | ||
} | ||
|
||
data <- dplyr::tribble( | ||
~STUDYID, ~USUBJID, | ||
"xyz", 123, | ||
"xyz", 456 | ||
) | ||
|
||
withr::local_options(lifecycle_verbosity = "quiet") | ||
expect_snapshot( | ||
example_fun(data), | ||
) | ||
|
||
}) | ||
|
||
## Test 2: Nicer message is sent to user ---- | ||
test_that("lifecycle_admiral Test 2: Nicer message is sent to user", { | ||
example_fun <- function(dataset) { | ||
deprecate_inform("1.0.0", "example_fun()", "example_fun2()", | ||
details = c( | ||
x = "Highly recommended to move to the suggested function", | ||
i = "See admiral's deprecation guidance: | ||
https://pharmaverse.github.io/admiraldev/dev/articles/programming_strategy.html#deprecation") #nolint | ||
) | ||
assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID)) | ||
} | ||
|
||
data <- dplyr::tribble( | ||
~STUDYID, ~USUBJID, | ||
"xyz", 123, | ||
"xyz", 456 | ||
) | ||
|
||
withr::local_options(lifecycle_verbosity = "quiet") | ||
expect_snapshot( | ||
example_fun(data), | ||
) | ||
|
||
}) |