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

catch empty datasets passed to unite #1574

Closed
bcjaeger opened this issue Sep 26, 2024 · 2 comments
Closed

catch empty datasets passed to unite #1574

bcjaeger opened this issue Sep 26, 2024 · 2 comments

Comments

@bcjaeger
Copy link

Hello, I stumbled on this by mistake and thought I'd open a PR given the error message.

It seems that unite could make an assertion about the shape of its input to prevent this.


Brief description of the problem: unite encounters an internal error if the input data is empty.

library(tibble)
library(tidyr)
options(error = traceback)
tibble(x=NULL) %>% unite(col='tmp', everything())
#> Error in `df_append()`:
#> ! `after` must be a whole number, not an integer `NA`.
#> ℹ This is an internal error that was detected in the tidyr package.
#>   Please report it at <https://github.com/tidyverse/tidyr/issues> with a reprex
#>   (<https://tidyverse.org/help/>) and the full backtrace.
#> Backtrace:
#>     ▆
#>  1. ├─tibble(x = NULL) %>% unite(col = "tmp", everything())
#>  2. ├─tidyr::unite(., col = "tmp", everything())
#>  3. └─tidyr:::unite.data.frame(., col = "tmp", everything())
#>  4.   └─tidyr:::df_append(after = after)
#>  5.     └─tidyr:::check_number_whole(after, min = 0L, max = n, .internal = TRUE)
#>  6.       └─tidyr:::.rlang_types_check_number(...)
#>  7.         └─tidyr (local) .stop(x, what, ...)
#>  8.           └─tidyr:::stop_input_type(...)
#>  9.             └─rlang::abort(message, ..., call = call, arg = arg)

Created on 2024-09-25 with reprex v2.0.2

@DavisVaughan
Copy link
Member

This actually works in the dev version of tidyr and gives

# A tibble: 0 × 1
# ℹ 1 variable: tmp <chr>

unite() has a guarantee that it will always generate the col column, regardless of how many columns you provide it, and we uphold that now even in the empty data frame case

@bcjaeger
Copy link
Author

Nice - thank you!

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

2 participants