Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Depends:
R (>= 3.6)
Imports:
cli (>= 3.4.0),
glue,
rlang (>= 1.1.0)
Suggests:
covr,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# lifecycle (development version)

* `deprecate_soft()` and `deprecate_warn()` are faster thanks to some internal refactoring.

* `deprecate_soft()` now actually warns after every 8 hours.

* Improvements to `lint_lifecycle()` and `lint_tidyverse_lifecycle()` (@AshesITR):
* Updated to support lintr >= 3.0.0 (#178).
* Fixed default `pattern=` argument to only find R files (#165).
Expand Down
26 changes: 12 additions & 14 deletions R/deprecate.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,24 +306,22 @@ lifecycle_message <- function(when,
}

lifecycle_message_what <- function(what, when) {
glue_what <- function(x) glue::glue_data(what, x)

if (!inherits(what$fn, "AsIs")) {
what$fn <- fun_label(what$fn)
}

if (is_null(what$arg)) {
if (what$from == "deprecate_stop") {
glue_what("{ fn } was deprecated in { pkg } { when } and is now defunct.")
sprintf("%s was deprecated in %s %s and is now defunct.", what$fn, what$pkg, when)
} else {
glue_what("{ fn } was deprecated in { pkg } { when }.")
sprintf("%s was deprecated in %s %s.", what$fn, what$pkg, when)
}
} else {
if (what$from == "deprecate_stop" && is_null(what$reason)) {
glue_what("The `{ arg }` argument of { fn } was deprecated in { pkg } { when } and is now defunct.")
sprintf("The `%s` argument of %s was deprecated in %s %s and is now defunct.", what$arg, what$fn, what$pkg, when)
} else {
what$reason <- what$reason %||% "is deprecated"
glue_what("The `{ arg }` argument of { fn } { reason } as of { pkg } { when }.")
sprintf("The `%s` argument of %s %s as of %s %s.", what$arg, what$fn, what$reason, what$pkg, when)
}
}
}
Expand All @@ -337,21 +335,19 @@ fun_label <- function(fn) {
}

lifecycle_message_with <- function(with, what) {
glue_with <- function(x) glue::glue_data(with, x)

if (inherits(with$fn, "AsIs")) {
glue_with("Please use { fn } instead.")
sprintf("Please use %s instead.", with$fn)
} else {
if (!is_null(with$pkg) && what$pkg != with$pkg) {
with$fn <- glue_with("{ pkg }::{ fn }")
with$fn <- sprintf("%s::%s", with$pkg, with$fn)
}

if (is_null(with$arg)) {
glue_with("Please use `{ fn }()` instead.")
sprintf("Please use `%s()` instead.", with$fn)
} else if (what$fn == with$fn) {
glue_with("Please use the `{ arg }` argument instead.")
sprintf("Please use the `%s` argument instead.", with$arg)
} else {
glue_with("Please use the `{ arg }` argument of `{ fn }()` instead.")
sprintf("Please use the `%s` argument of `%s()` instead.", with$arg, with$fn)
}
}
}
Expand Down Expand Up @@ -408,5 +404,7 @@ needs_warning <- function(id, call = caller_env()) {
}

# Warn every 8 hours
(Sys.time() - last) > (8 * 60 * 60)
# Must unclass to ensure we always compare in units of seconds, also much
# faster this way.
(unclass(Sys.time()) - unclass(last)) > (8 * 60 * 60)
}
6 changes: 3 additions & 3 deletions R/signal.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#' }
#' foofy(1, 2, 3)
signal_stage <- function(stage, what, with = NULL, env = caller_env()) {
stage <- arg_match(stage, c("experimental", "superseded", "deprecated"))
stage <- arg_match0(stage, c("experimental", "superseded", "deprecated"))
what <- spec(what, env = env)

if (is_null(what$arg)) {
msg <- glue::glue_data(what, "{fn}() is {stage}")
msg <- sprintf("%s() is %s", what$fn, stage)
} else {
msg <- glue::glue_data(what, "{fn}(arg) is {stage}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(arg) here should have been ({arg})

msg <- sprintf("%s(%s) is %s", what$fn, what$arg, stage)
}

if (!is_null(with)) {
Expand Down
16 changes: 9 additions & 7 deletions R/verbosity.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ lifecycle_verbosity <- function() {

if (!is_string(opt, c("quiet", "default", "warning", "error"))) {
options(lifecycle_verbosity = "default")
warn(glue::glue(
"
The `lifecycle_verbosity` option must be set to one of:
\"quiet\", \"default\", \"warning\", or \"error\".
Resetting to \"default\".
"
))

message <- paste(
sep = " ",
"The `lifecycle_verbosity` option must be set to one of:",
"\"quiet\", \"default\", \"warning\", or \"error\".",
"Resetting to \"default\"."
)

warn(message)
}

opt
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/signal.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Code
(expect_condition(signal_stage("superseded", "foo(bar)")))
Output
<lifecycle_stage: foo(arg) is superseded>
<lifecycle_stage: foo(bar) is superseded>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually had a bug here where ({arg}) wasn't being interpolated


# signal_stage supports with

Expand All @@ -19,6 +19,6 @@
Code
(expect_condition(signal_stage("superseded", "foo(bar=)", "foo(baz=)")))
Output
<lifecycle_stage: foo(arg) is superseded
<lifecycle_stage: foo(bar) is superseded
Please use the `baz` argument instead.>

3 changes: 2 additions & 1 deletion tests/testthat/test-deprecate.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ test_that("needs_warning works as expected", {
env_poke(deprecation_env, "test", Sys.time())
expect_false(needs_warning("test"))

# More than 8 hours
env_poke(deprecation_env, "test", Sys.time() - 9 * 60 * 60)
expect_false(needs_warning("test"))
expect_true(needs_warning("test"))
Comment on lines +216 to +218
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This incorrect test started "failing" all of a sudden after I started unclass()ing the POSIXct, which is how I found the bug


env_poke(deprecation_env, "test", "x")
expect_snapshot_error(needs_warning("test"))
Expand Down
Loading