From 46b63448dc790d94c4fbcbf81dd4ff9cc32aa32e Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Fri, 2 Sep 2022 10:43:22 +0200 Subject: [PATCH] Rename `dplyr_last_warnings()` to `last_dplyr_warnings()` To namespace it in `last_` for autocompletion --- NAMESPACE | 4 +-- NEWS.md | 2 +- R/conditions.R | 12 +++---- ...ast_warnings.Rd => last_dplyr_warnings.Rd} | 8 ++--- tests/testthat/_snaps/conditions.md | 34 +++++++++---------- tests/testthat/test-conditions.R | 16 ++++----- 6 files changed, 38 insertions(+), 38 deletions(-) rename man/{dplyr_last_warnings.Rd => last_dplyr_warnings.Rd} (82%) diff --git a/NAMESPACE b/NAMESPACE index a9d944efdd..0babfb7de7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) @@ -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) diff --git a/NEWS.md b/NEWS.md index 847fdf7529..8c404c53f9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/conditions.R b/R/conditions.R index e9098f90d4..a84c8dd331 100644 --- a/R/conditions.R +++ b/R/conditions.R @@ -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) @@ -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 ) } @@ -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}." )) } @@ -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 @@ -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." )) } } diff --git a/man/dplyr_last_warnings.Rd b/man/last_dplyr_warnings.Rd similarity index 82% rename from man/dplyr_last_warnings.Rd rename to man/last_dplyr_warnings.Rd index 545e67d241..eb782f0178 100644 --- a/man/dplyr_last_warnings.Rd +++ b/man/last_dplyr_warnings.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/conditions.R -\name{dplyr_last_warnings} -\alias{dplyr_last_warnings} +\name{last_dplyr_warnings} +\alias{last_dplyr_warnings} \title{Show warnings from the last command} \usage{ -dplyr_last_warnings(n = 5) +last_dplyr_warnings(n = 5) } \arguments{ \item{n}{Passed to \code{\link[=head]{head()}} so that only the first \code{n} warnings are @@ -15,5 +15,5 @@ Warnings that occur inside a dplyr verb like \code{mutate()} are caught 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 -\code{dplyr_last_warnings()}. +\code{last_dplyr_warnings()}. } diff --git a/tests/testthat/_snaps/conditions.md b/tests/testthat/_snaps/conditions.md index 89b473d967..91d604d644 100644 --- a/tests/testthat/_snaps/conditions.md +++ b/tests/testthat/_snaps/conditions.md @@ -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 @@ -236,7 +236,7 @@ There was 1 warning in a `mutate()` step. ! msg Code - dplyr_last_warnings() + last_dplyr_warnings() Output [[1]] @@ -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]] @@ -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]] @@ -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]] @@ -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: @@ -522,7 +522,7 @@ 1 1 1 2 2 1 Code - dplyr_last_warnings(n = 1) + last_dplyr_warnings(n = 1) Output [[1]] @@ -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. --- @@ -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: @@ -571,7 +571,7 @@ 4 4 1 5 5 1 Code - dplyr_last_warnings(n = 1) + last_dplyr_warnings(n = 1) Output [[1]] @@ -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 @@ -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] @@ -619,7 +619,7 @@ 2 2 1 3 3 1 Code - dplyr_last_warnings() + last_dplyr_warnings() Output [[1]] diff --git a/tests/testthat/test-conditions.R b/tests/testthat/test-conditions.R index 53d5e04aea..86b8b8290f 100644 --- a/tests/testthat/test-conditions.R +++ b/tests/testthat/test-conditions.R @@ -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 ) @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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) }) }) @@ -167,6 +167,6 @@ test_that("complex backtraces with base and rlang warnings", { expect_snapshot({ foo() - dplyr_last_warnings() + last_dplyr_warnings() }) })