Skip to content

Commit

Permalink
feat: #466 include all arguments; todo: figure out NA issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bms63 committed Dec 20, 2024
1 parent dd48670 commit 9afde36
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 54 deletions.
31 changes: 19 additions & 12 deletions R/lifecycle_admiral.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
#'
#' Wrapper around `lifecycle::deprecate_soft()`.
#'
#' @param when See documentation for `lifecycle::deprecate_soft()`.
#' @param what See documentation for `lifecycle::deprecate_soft()`.
#' @param with See documentation for `lifecycle::deprecate_soft()`.
#' @param details See documentation for `lifecycle::deprecate_soft()`.
#' @param id See documentation for `lifecycle::deprecate_soft()`.
#' @param env See documentation for `lifecycle::deprecate_soft()`.
#'
#' @param user_env See documentation for `lifecycle::deprecate_soft()`.
#'
#' @param ... See documentation for `lifecycle::deprecate_soft()` for additional argument use.
#'
#'
#'
#' @return `NULL`, invisibly.
#'
#' @examples
Expand All @@ -18,7 +17,7 @@
#' when = "1.0.0",
#' what = "foo()",
#' details = c(
#' # 'x = "This message will turn into a warning with release of x.y.z",
#' x = "This message will turn into a warning with release of x.y.z",
#' i = "See admiral's deprecation guidance:
#' https://pharmaverse.github.io/admiraldev/dev/articles/programming_strategy.html#deprecation"
#' )
Expand All @@ -30,14 +29,22 @@
#'
#' @export
deprecate_inform <- function(
when,
what,
with = NULL,
details = NULL,
id = NULL,
env = caller_env(),
user_env = caller_env(2),
...) {
user_env = caller_env(2)) {
tryCatch(
lifecycle::deprecate_soft(
env = caller_env(),
user_env = caller_env(2),
...),
when = when,
what = what,
with = with,
details = details,
id = id,
env = env,
user_env = user_env),
warning = \(w) {
message(conditionMessage(w))
tryInvokeRestart("muffleWarning")
Expand Down
24 changes: 20 additions & 4 deletions man/deprecate_inform.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions tests/testthat/_snaps/lifecycle_admiral.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
# lifecycle_admiral Test 1: Message is sent to user
# lifecycle_admiral Test 1: Simple message is sent to user

Code
example_fun(data)
Message
`example_fun()` was deprecated in admiraldev 1.0.0.
`example_fun()` was deprecated in <NA> 1.0.0.
i Please use `example_fun2()` instead.
Code
example_fun(data)
Message
`example_fun()` was deprecated in <NA> 1.0.0.
i Please use `example_fun2()` instead.

# lifecycle_admiral Test 2: Nicer message is sent to user
# lifecycle_admiral Test 2: Spicier message is sent to user

Code
example_fun(data)
Message
`example_fun()` was deprecated in admiraldev 1.0.0.
`example_fun()` was deprecated in <NA> 1.0.0.
i Please use `example_fun2()` instead.
x This message will turn into a warning with release of 1.1.0
i See admiral's deprecation guidance: https://pharmaverse.github.io/admiraldev/dev/articles/programming_strategy.html#deprecation
Code
example_fun(data)
Message
`example_fun()` was deprecated in <NA> 1.0.0.
i Please use `example_fun2()` instead.
x This message will turn into a warning with release of 1.1.0
i See admiral's deprecation guidance: https://pharmaverse.github.io/admiraldev/dev/articles/programming_strategy.html#deprecation
Expand Down
30 changes: 0 additions & 30 deletions tests/testthat/_snaps/lifecycle_admiral.new.md

This file was deleted.

15 changes: 11 additions & 4 deletions tests/testthat/test-lifecycle_admiral.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## Test 1: Message is sent to user ----
test_that("lifecycle_admiral Test 1: Message is sent to user", {
test_that("lifecycle_admiral Test 1: Simple message is sent to user", {
example_fun <- function(dataset) {
deprecate_inform("1.0.0", "example_fun()", "example_fun2()")
deprecate_inform(
when = "1.0.0",
what = "example_fun()",
with = "example_fun2()"
)
assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID))
}

Expand All @@ -18,9 +22,12 @@ test_that("lifecycle_admiral Test 1: Message is sent to user", {
})

# Test 2: Nicer message is sent to user ----
test_that("lifecycle_admiral Test 2: Nicer message is sent to user", {
test_that("lifecycle_admiral Test 2: Spicier message is sent to user", {
example_fun <- function(dataset) {
deprecate_inform("1.0.0", "example_fun()", "example_fun2()",
deprecate_inform(
when = "1.0.0",
what = "example_fun()",
with = "example_fun2()",
details = c(
x = "This message will turn into a warning with release of 1.1.0",
i = "See admiral's deprecation guidance:
Expand Down

0 comments on commit 9afde36

Please sign in to comment.