dplyr
dplyr copied to clipboard
`summarise()` and `reframe()` turns warnings from inside functions as errors
Please briefly describe your problem and what output you expect. If you have a question, please don't use this form. Instead, ask on https://stackoverflow.com/ or https://community.rstudio.com/.
Please include a minimal reproducible example (AKA a reprex). If you've never heard of a reprex before, start by reading https://www.tidyverse.org/help/#reprex.
In the following example, the dplyr warning will result into an error:
suppressPackageStartupMessages(library(dplyr))
f <- function() {
data.frame(id = 1:2) |>
summarise(n = warning("test"), .by = "id")
}
mtcars |>
reframe(f(), .by = "gear")
#> Error:
#> ! Failed to evaluate glue component {label}
#> Caused by error in `vapply()`:
#> ! values must be length 1,
#> but FUN(X[[1]]) result is length 0
Created on 2024-04-02 with reprex v2.1.0
I just ran into this error, and am glad to find it documented here. It is strange and disruptive behavior that a warning in the function f() escalates to an error when f() is applied with reframe. The error message is also unhelpful. Note that the same thing happens when using summarize() instead of reframe().