Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/complete.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)

Expand Down
2 changes: 1 addition & 1 deletion R/expand.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)

Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/test-complete.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
})
13 changes: 13 additions & 0 deletions tests/testthat/test-expand.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down