tidyverse / dplyr

dplyr: A grammar of data manipulation
https://dplyr.tidyverse.org/
Other
4.78k stars 2.12k forks source link

`summarise()` and `reframe()` turns warnings from inside functions as errors #7008

Open psychelzh opened 7 months ago

psychelzh commented 7 months ago

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

kelliemac commented 5 months ago

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().