diff --git a/R/complete.R b/R/complete.R index 1f6591bf..3f9b3fe0 100644 --- a/R/complete.R +++ b/R/complete.R @@ -99,8 +99,8 @@ complete.grouped_df <- function(data, ..., fill = list(), explicit = TRUE) { complete( data = dplyr::pick(everything()), ..., - fill = fill, - explicit = explicit + fill = .env$fill, + explicit = .env$explicit ) ) diff --git a/R/expand.R b/R/expand.R index 5d846bde..47aa200f 100644 --- a/R/expand.R +++ b/R/expand.R @@ -106,7 +106,7 @@ expand.grouped_df <- function(data, ..., .name_repair = "check_unique") { expand( data = dplyr::pick(everything()), ..., - .name_repair = .name_repair + .name_repair = .env$.name_repair ) ) diff --git a/tests/testthat/test-complete.R b/tests/testthat/test-complete.R index 3e3d9511..0e54b2f3 100644 --- a/tests/testthat/test-complete.R +++ b/tests/testthat/test-complete.R @@ -201,3 +201,29 @@ test_that("validates its inputs", { complete(mtcars, explicit = 1) }) }) + +test_that("works when `fill` is a column name in a grouped df (#1575)", { + df <- tibble( + g = c(1, NA), + fill = factor(1:2, levels = 1:3) + ) + gdf <- dplyr::group_by(df, g) + + expect_identical( + complete(gdf, fill)$g, + c(1, 1, 1, NA, NA, NA) + ) +}) + +test_that("works when `explicit` is a column name in a grouped df (#1575)", { + df <- tibble( + g = c(1, NA), + explicit = factor(1:2, levels = 1:3) + ) + gdf <- dplyr::group_by(df, g) + + expect_identical( + complete(gdf, explicit)$g, + c(1, 1, 1, NA, NA, NA) + ) +}) diff --git a/tests/testthat/test-expand.R b/tests/testthat/test-expand.R index a790c026..26e30852 100644 --- a/tests/testthat/test-expand.R +++ b/tests/testthat/test-expand.R @@ -177,6 +177,19 @@ test_that("expand() retains `NA` data in factors (#1275)", { ) }) +test_that("expand() works on grouped data with `.name_repair` column (#1575)", { + df <- tibble( + g = c(1, NA), + .name_repair := factor(1:2, levels = 1:3) + ) + gdf <- dplyr::group_by(df, g) + + expect_identical( + expand(gdf, .name_repair)$g, + c(1, 1, 1, NA, NA, NA) + ) +}) + # ------------------------------------------------------------------------------ test_that("crossing checks for bad inputs", {