Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rowwise() and empty input #7039

Open
krlmlr opened this issue Jun 12, 2024 · 0 comments
Open

rowwise() and empty input #7039

krlmlr opened this issue Jun 12, 2024 · 0 comments

Comments

@krlmlr
Copy link
Member

krlmlr commented Jun 12, 2024

Should we guarantee that the functions used in a rowwise mutate() or summarize() or reframe() always see length-one input? This is currently the case for everything but empty input, which creates a corner case to be worked around in user code. The example below shows mutate(), but the behavior is very similar for summarize() and reframe()

options(conflicts.policy = list(warn = FALSE))

library(dplyr)

tibble(a = 1L) |>
  rowwise() |>
  mutate(print(a))
#> [1] 1
#> # A tibble: 1 × 2
#> # Rowwise: 
#>       a `print(a)`
#>   <int>      <int>
#> 1     1          1
tibble(a = 1:3) |>
  rowwise() |>
  mutate(print(a))
#> [1] 1
#> [1] 2
#> [1] 3
#> # A tibble: 3 × 2
#> # Rowwise: 
#>       a `print(a)`
#>   <int>      <int>
#> 1     1          1
#> 2     2          2
#> 3     3          3
# Should this print `NA_integer_` ?
tibble(a = integer()) |>
  rowwise() |>
  mutate(print(a))
#> integer(0)
#> # A tibble: 0 × 2
#> # Rowwise: 
#> # ℹ 2 variables: a <int>, print(a) <int>

Created on 2024-06-12 with reprex v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant