Skip to content

Commit

Permalink
Require data frame compatibility for setequal()
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Mar 17, 2023
1 parent d4acc5e commit 0589584
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
7 changes: 1 addition & 6 deletions R/sets.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ setdiff.data.frame <- function(x, y, ...) {
#' @export
setequal.data.frame <- function(x, y, ...) {
check_dots_empty()
if (!is.data.frame(y)) {
abort("`y` must be a data frame.")
}
if (!isTRUE(is_compatible(x, y))) {
return(FALSE)
}
check_compatible(x, y)

cast <- vec_cast_common(x = x, y = y)
all(vec_in(cast$x, cast$y)) && all(vec_in(cast$y, cast$x))
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/_snaps/sets.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
setequal(mtcars, 1)
Condition
Error in `setequal()`:
! `y` must be a data frame.
! `x` and `y` are not compatible.
`y` must be a data frame.

# setequal checks for extra arguments

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-sets.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ test_that("setequal uses coercion rules (#6114)", {
})

test_that("setequal tibbles must have same rows and columns", {
expect_false(setequal(tibble(x = 1:2), tibble(y = 1:2)))
expect_error(setequal(tibble(x = 1:2), tibble(y = 1:2)))
expect_false(setequal(tibble(x = 1:2), tibble(x = 2:3)))
expect_false(setequal(tibble(x = 1:2), tibble(x = c("a", "b"))))
expect_error(setequal(tibble(x = 1:2), tibble(x = c("a", "b"))))
})

test_that("setequal checks y is a data frame", {
Expand Down

0 comments on commit 0589584

Please sign in to comment.