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

Return logical() from vec_equal_na(NULL) #1497

Merged
merged 2 commits into from
Jan 31, 2022
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# vctrs (development version)

* `vec_equal_na(NULL)` now returns `logical(0)` rather than erroring (#1494).

* `vec_as_location(missing = "error")` now fails with `NA` and `NA_character_`
in addition to `NA_integer_` (#1420, @krlmlr).

Expand Down
4 changes: 4 additions & 0 deletions src/equal.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ SEXP vec_equal_na(SEXP x) {
UNPROTECT(1);
return out;
}
case vctrs_type_null: {
UNPROTECT(1);
return vctrs_shared_empty_lgl;
}
case vctrs_type_scalar: Rf_errorcall(R_NilValue, "Can't detect `NA` values in scalars with `vctrs_equal_na()`.");
default: Rf_error("Unimplemented type in `vctrs_equal_na()`.");
}
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-equal.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ test_that("works recursively with data frame columns", {
expect_equal(vec_equal_na(df), c(FALSE, FALSE, FALSE, TRUE))
})

test_that("works with `NULL` input (#1494)", {
expect_identical(vec_equal_na(NULL), logical())
})

test_that("NA propagate symmetrically (#204)", {
exp <- c(NA, NA)

Expand Down