dplyr icon indicating copy to clipboard operation
dplyr copied to clipboard

`Error in vapply(.x, .f, .mold, ..., USE.NAMES = FALSE)`: cli_warn together with dplyr grouping results in error.

Open lschneiderbauer opened this issue 2 years ago • 3 comments

Hi,

it took me a while to get to this (very artificial) reduced example, but I managed to get it: For some reason, using cli::warn() inside a nested and grouped mutate function results in the described error.

Removing cli_warn() also removes the error and results in a sane answer.

I am using R 4.2.1, with dplyr 1.1.3 and cli 3.6.1.


Brief description of the problem

library(cli)
library(dplyr)
#> 
#> Attache Paket: 'dplyr'
#> Die folgenden Objekte sind maskiert von 'package:stats':
#> 
#>     filter, lag
#> Die folgenden Objekte sind maskiert von 'package:base':
#> 
#>     intersect, setdiff, setequal, union

some_warning <- function() {
  cli::cli_warn("some warning")
  return(1)
}

create_new_col <- function() {
  tibble(col = TRUE) |>
    mutate(
      new_col = some_warning(),
      .by = col
    ) |>
    pull(new_col)
}

tibble(group = TRUE) |>
  mutate(new_col = create_new_col(), .by = group)
#> Error in vapply(.x, .f, .mold, ..., USE.NAMES = FALSE): Werte müssen die Länge 1 haben,
#> Ergebnis von FUN(X[[1]]) hat aber Länge 0

Created on 2023-10-10 with reprex v2.0.2

lschneiderbauer avatar Oct 10 '23 16:10 lschneiderbauer

Slightly more minimal reprex, seems to be some kind of issue with the outer and inner group information in combination with our warning handler

library(dplyr, warn.conflicts = FALSE)

some_warning <- function() {
  warning("oh no")
  1
}

create_new_col <- function() {
  df <- tibble(col = 1)
  mutate(df, y = some_warning(), .by = col)
}

tibble(group = 1) |>
  mutate(x = create_new_col(), .by = group)
#> Error in vapply(.x, .f, .mold, ..., USE.NAMES = FALSE): values must be length 1,
#>  but FUN(X[[1]]) result is length 0

Created on 2023-11-06 with reprex v2.0.2

DavisVaughan avatar Nov 06 '23 15:11 DavisVaughan

+1 (???)

Steviey avatar Apr 14 '24 16:04 Steviey

Failed to evaluate glue component {label} How to suppress this?

image

Steviey avatar Apr 29 '24 16:04 Steviey