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

Ignore columns that evaluate to NULL #902

Merged
merged 3 commits into from
Jul 17, 2021
Merged
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
14 changes: 7 additions & 7 deletions R/tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ tibble <- function(...,
.name_repair = c("check_unique", "unique", "universal", "minimal")) {
xs <- quos(...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is probably better practice for this to also be enquos()?


is.null <- map_lgl(xs, quo_is_null)

tibble_quos(xs[!is.null], .rows, .name_repair)
tibble_quos(xs, .rows, .name_repair)
}

#' tibble_row()
Expand All @@ -168,11 +166,9 @@ tibble <- function(...,
#' tibble_row(a = 1, lm = lm(Petal.Width ~ Petal.Length + Species, data = iris))
tibble_row <- function(...,
.name_repair = c("check_unique", "unique", "universal", "minimal")) {
xs <- quos(...)

is.null <- map_lgl(xs, quo_is_null)
xs <- enquos(...)

tibble_quos(xs[!is.null], .rows = 1, .name_repair = .name_repair, single_row = TRUE)
tibble_quos(xs, .rows = 1, .name_repair = .name_repair, single_row = TRUE)
}

#' Test if the object is a tibble
Expand Down Expand Up @@ -258,6 +254,10 @@ tibble_quos <- function(xs, .rows, .name_repair, single_row = FALSE) {
}

names(output) <- col_names

is_null <- map_lgl(output, is.null)
output <- output[!is_null]

output <- splice_dfs(output)
output <- set_repaired_names(output, repair_hint = TRUE, .name_repair = .name_repair)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper-testthat.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
options(testthat.progress.verbose_skips = FALSE)
options(Ncpus = parallel::detectCores())
#options(Ncpus = parallel::detectCores())
5 changes: 5 additions & 0 deletions tests/testthat/test-tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ test_that("NULL is ignored (#580)", {
expect_identical(tibble(b = 1, NULL, c = 2:3), tibble(b = 1, c = 2:3))
})

test_that("NULL is ignored when passed by value (#895, #900)", {
expect_identical(tibble(a = c()), tibble(a = NULL))
expect_identical(tibble(a = c(), a = 1), tibble(a = 1))
})

test_that("bogus columns raise an error", {
expect_tibble_error(
tibble(a = new.env()),
Expand Down