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

complete fails when fill is a column name in a grouped df #1575

Open
pwwang opened this issue Sep 30, 2024 · 1 comment
Open

complete fails when fill is a column name in a grouped df #1575

pwwang opened this issue Sep 30, 2024 · 1 comment
Labels
bug an unexpected problem or unintended behavior grids #️⃣ expanding, nesting, crossing, ...

Comments

@pwwang
Copy link

pwwang commented Sep 30, 2024

When there is a column called fill in a grouped data frame, complete always fails.

r$> library(tidyr)
 
    data <- tibble::tibble(
        x = factor(rep(c("A", "B"), 2), levels = c("A", "B", "C")),
        y = c(1, 3, 6, 4),
        fill = rep(c("F1", "F2"), each = 2)
    )
    data
# A tibble: 4 × 3
  x         y fill 
  <fct> <dbl> <chr>
1 A         1 F1   
2 B         3 F1   
3 A         6 F2   
4 B         4 F2   

r$> data |> complete(x)
# A tibble: 5 × 3
  x         y fill 
  <fct> <dbl> <chr>
1 A         1 F1   
2 A         6 F2   
3 B         3 F1   
4 B         4 F2   
5 C        NA NA   

r$> data |> dplyr::group_by(y) |> complete(x)
Error in `reframe()`:In argument: `complete(data = pick(everything()), ..., fill = fill, explicit = explicit)`.In group 1: `y = 1`.
Caused by error in `replace_na()`:
! `replace` must be a list, not a string.
Run `rlang::last_trace()` to see where the error occurred.

r$> data |> dplyr::group_by(fill) |> complete(x)
Error in `reframe()`:In argument: `complete(data = pick(everything()), ..., fill = fill, explicit = explicit)`.In group 1: `fill = "F1"`.
Caused by error in `replace_na()`:
! `replace` must be a list, not a character vector.
Run `rlang::last_trace()` to see where the error occurred.

r$> data$fill1 <- data$fill; data$fill <- NULL

r$> data |> dplyr::group_by(fill1) |> complete(x)
# A tibble: 6 × 3
# Groups:   fill1 [2]
  fill1 x         y
  <chr> <fct> <dbl>
1 F1    A         1
2 F1    B         3
3 F1    C        NA
4 F2    A         6
5 F2    B         4
6 F2    C        NA

r$> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-conda-linux-gnu
Running under: Ubuntu 24.04 LTS

Matrix products: default
BLAS/LAPACK: /path/to/lib/libopenblasp-r0.3.27.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8      
 [8] LC_NAME=C              LC_ADDRESS=C           LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: America/Los_Angeles
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tidyr_1.3.1

loaded via a namespace (and not attached):
 [1] utf8_1.2.4       R6_2.5.1         tidyselect_1.2.1 magrittr_2.0.3   glue_1.7.0       tibble_3.2.1     pkgconfig_2.0.3  dplyr_1.1.4      generics_0.1.3   lifecycle_1.0.4 
[11] cli_3.6.3        fansi_1.0.6      vctrs_0.6.5      withr_3.0.1      compiler_4.4.1   purrr_1.0.2      pillar_1.9.0     rlang_1.1.4     
@DavisVaughan
Copy link
Member

Ah, I think tidyr:::complete.grouped_df() needs to do .env$fill and .env$explicit when passing them through since they go into a dplyr function (which will use column names first if they exist).

Probably also look at tidyr:::expand.grouped_df() and do the same with .name_repair

@DavisVaughan DavisVaughan added bug an unexpected problem or unintended behavior grids #️⃣ expanding, nesting, crossing, ... labels Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior grids #️⃣ expanding, nesting, crossing, ...
Projects
None yet
Development

No branches or pull requests

2 participants