Skip to content

Commit

Permalink
Rename dplyr_last_warnings() to last_dplyr_warnings()
Browse files Browse the repository at this point in the history
To namespace it in `last_` for autocompletion
  • Loading branch information
lionel- committed Sep 8, 2022
1 parent 32a985b commit 46b6344
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ S3method(nest_join,data.frame)
S3method(print,all_vars)
S3method(print,any_vars)
S3method(print,dplyr_join_by)
S3method(print,dplyr_last_warnings)
S3method(print,dplyr_sel_vars)
S3method(print,fun_list)
S3method(print,last_dplyr_warnings)
S3method(print,src)
S3method(pull,data.frame)
S3method(rbind,grouped_df)
Expand Down Expand Up @@ -272,7 +272,6 @@ export(distinct_prepare)
export(do)
export(do_)
export(dplyr_col_modify)
export(dplyr_last_warnings)
export(dplyr_reconstruct)
export(dplyr_row_slice)
export(ends_with)
Expand Down Expand Up @@ -336,6 +335,7 @@ export(join_by)
export(lag)
export(last)
export(last_col)
export(last_dplyr_warnings)
export(lead)
export(left_join)
export(location)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# dplyr (development version)

* Warnings emitted inside `mutate()` and variants are now collected and stashed
away. Run the new `dplyr_last_warnings()` function to see the warnings emitted
away. Run the new `last_dplyr_warnings()` function to see the warnings emitted
within dplyr verbs during the last top-level command.

This fixes performance issues when throusands of warnings are emitted with
Expand Down
12 changes: 6 additions & 6 deletions R/conditions.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ skip_internal_condition <- function(cnd) {
#' and stashed away instead of being emitted to the console. This
#' prevents rowwise and grouped data frames from flooding the console
#' with warnings. To see the original warnings, use
#' `dplyr_last_warnings()`.
#' `last_dplyr_warnings()`.
#'
#' @param n Passed to [head()] so that only the first `n` warnings are
#' displayed.
#' @export
dplyr_last_warnings <- function(n = 5) {
last_dplyr_warnings <- function(n = 5) {
if (!identical(n, Inf)) {
check_number(n)
stopifnot(n >= 0)
Expand All @@ -205,7 +205,7 @@ dplyr_last_warnings <- function(n = 5) {

structure(
warnings,
class = c("dplyr_last_warnings", "list"),
class = c("last_dplyr_warnings", "list"),
remaining = remaining
)
}
Expand Down Expand Up @@ -246,7 +246,7 @@ signal_warnings <- function(warnings, error_call) {
"There {cli::qty(n)} {?was/were} {n} warning{?s} in a {call} step.",
if (n > 1) "The first warning was:",
cnd_message_lines(first),
i = if (n > 1) "Run `dplyr::dplyr_last_warnings()` to see the {n - 1} remaining warning{?s}."
i = if (n > 1) "Run `dplyr::last_dplyr_warnings()` to see the {n - 1} remaining warning{?s}."
))
}

Expand All @@ -271,7 +271,7 @@ new_dplyr_warning <- function(data) {
}

#' @export
print.dplyr_last_warnings <- function(x, ...) {
print.last_dplyr_warnings <- function(x, ...) {
# Opt into experimental grayed out tree
local_options(
"rlang:::trace_display_tree" = TRUE
Expand All @@ -282,7 +282,7 @@ print.dplyr_last_warnings <- function(x, ...) {
if (remaining) {
cli::cli_bullets(c(
"... with {remaining} more warning{?s}.",
"i" = "Use {.code dplyr_last_warnings(n = ...)} to show more."
"i" = "Use {.code last_dplyr_warnings(n = ...)} to show more."
))
}
}
Expand Down
8 changes: 4 additions & 4 deletions man/dplyr_last_warnings.Rd → man/last_dplyr_warnings.Rd

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

34 changes: 17 additions & 17 deletions tests/testthat/_snaps/conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
Error in `foobarbaz()`:
! could not find function "foobarbaz"

# warnings are collected for `dplyr_last_warnings()`
# warnings are collected for `last_dplyr_warnings()`

Code
# Ungrouped
Expand All @@ -236,7 +236,7 @@
There was 1 warning in a `mutate()` step.
! msg
Code
dplyr_last_warnings()
last_dplyr_warnings()
Output
[[1]]
<warning/rlang_warning>
Expand Down Expand Up @@ -269,9 +269,9 @@
There were 2 warnings in a `mutate()` step.
The first warning was:
! msg
i Run `dplyr::dplyr_last_warnings()` to see the 1 remaining warning.
i Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
Code
dplyr_last_warnings()
last_dplyr_warnings()
Output
[[1]]
<warning/rlang_warning>
Expand Down Expand Up @@ -324,9 +324,9 @@
There were 2 warnings in a `mutate()` step.
The first warning was:
! msg
i Run `dplyr::dplyr_last_warnings()` to see the 1 remaining warning.
i Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
Code
dplyr_last_warnings()
last_dplyr_warnings()
Output
[[1]]
<warning/rlang_warning>
Expand Down Expand Up @@ -383,14 +383,14 @@
There were 2 warnings in a `mutate()` step.
The first warning was:
! msg
i Run `dplyr::dplyr_last_warnings()` to see the 1 remaining warning.
i Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
Warning:
There were 2 warnings in a `mutate()` step.
The first warning was:
! msg
i Run `dplyr::dplyr_last_warnings()` to see the 1 remaining warning.
i Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
Code
dplyr_last_warnings()
last_dplyr_warnings()
Output
[[1]]
<warning/rlang_warning>
Expand Down Expand Up @@ -513,7 +513,7 @@
There were 2 warnings in a `mutate()` step.
The first warning was:
! msg
i Run `dplyr::dplyr_last_warnings()` to see the 1 remaining warning.
i Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
Output
# A tibble: 2 x 2
# Rowwise:
Expand All @@ -522,7 +522,7 @@
1 1 1
2 2 1
Code
dplyr_last_warnings(n = 1)
last_dplyr_warnings(n = 1)
Output
[[1]]
<warning/rlang_warning>
Expand All @@ -546,7 +546,7 @@
Message
... with 1 more warning.
i Use `dplyr_last_warnings(n = ...)` to show more.
i Use `last_dplyr_warnings(n = ...)` to show more.

---

Expand All @@ -559,7 +559,7 @@
There were 5 warnings in a `mutate()` step.
The first warning was:
! msg
i Run `dplyr::dplyr_last_warnings()` to see the 4 remaining warnings.
i Run `dplyr::last_dplyr_warnings()` to see the 4 remaining warnings.
Output
# A tibble: 5 x 2
# Rowwise:
Expand All @@ -571,7 +571,7 @@
4 4 1
5 5 1
Code
dplyr_last_warnings(n = 1)
last_dplyr_warnings(n = 1)
Output
[[1]]
<warning/rlang_warning>
Expand All @@ -595,7 +595,7 @@
Message
... with 4 more warnings.
i Use `dplyr_last_warnings(n = ...)` to show more.
i Use `last_dplyr_warnings(n = ...)` to show more.

# complex backtraces with base and rlang warnings

Expand All @@ -609,7 +609,7 @@
There were 3 warnings in a `mutate()` step.
The first warning was:
! foo
i Run `dplyr::dplyr_last_warnings()` to see the 2 remaining warnings.
i Run `dplyr::last_dplyr_warnings()` to see the 2 remaining warnings.
Output
# A tibble: 3 x 2
# Groups: x [1]
Expand All @@ -619,7 +619,7 @@
2 2 1
3 3 1
Code
dplyr_last_warnings()
last_dplyr_warnings()
Output
[[1]]
<warning/rlang_warning>
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-conditions.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test_that("errors during dots collection are not enriched (#6178)", {
})
})

test_that("warnings are collected for `dplyr_last_warnings()`", {
test_that("warnings are collected for `last_dplyr_warnings()`", {
local_options(
rlang_trace_format_srcrefs = FALSE
)
Expand All @@ -83,7 +83,7 @@ test_that("warnings are collected for `dplyr_last_warnings()`", {
df |>
mutate(x = f()) |>
invisible()
dplyr_last_warnings()
last_dplyr_warnings()
})

reset_dplyr_warnings()
Expand All @@ -93,7 +93,7 @@ test_that("warnings are collected for `dplyr_last_warnings()`", {
group_by(id) |>
mutate(x = f()) |>
invisible()
dplyr_last_warnings()
last_dplyr_warnings()
})

reset_dplyr_warnings()
Expand All @@ -103,7 +103,7 @@ test_that("warnings are collected for `dplyr_last_warnings()`", {
rowwise() |>
mutate(x = f()) |>
invisible()
dplyr_last_warnings()
last_dplyr_warnings()
})

reset_dplyr_warnings()
Expand All @@ -116,7 +116,7 @@ test_that("warnings are collected for `dplyr_last_warnings()`", {
group_by(id) |>
mutate(x = f()) |>
invisible()
dplyr_last_warnings()
last_dplyr_warnings()
})

reset_dplyr_warnings()
Expand All @@ -125,7 +125,7 @@ test_that("warnings are collected for `dplyr_last_warnings()`", {
df |>
rowwise() |>
mutate(x = f())
dplyr_last_warnings(n = 1)
last_dplyr_warnings(n = 1)
})

reset_dplyr_warnings()
Expand All @@ -135,7 +135,7 @@ test_that("warnings are collected for `dplyr_last_warnings()`", {
df |>
rowwise() |>
mutate(x = f())
dplyr_last_warnings(n = 1)
last_dplyr_warnings(n = 1)
})
})

Expand Down Expand Up @@ -167,6 +167,6 @@ test_that("complex backtraces with base and rlang warnings", {

expect_snapshot({
foo()
dplyr_last_warnings()
last_dplyr_warnings()
})
})

0 comments on commit 46b6344

Please sign in to comment.