1test_that("[.tbl_df supports subsetting with a logical matrix (#649)", { 2 foo <- tibble(x = 1:10, y = 1:10, z = letters[1:10]) 3 4 m <- matrix(c(rep(FALSE, 8), rep(TRUE, 3), rep(FALSE, 19)), ncol = 3) 5 expect_equal(foo[m], c(9, 10, 1)) 6 7 m <- matrix(c(rep(FALSE, 18), rep(TRUE, 3), rep(FALSE, 9)), ncol = 3) 8 expect_error(foo[m], class = "vctrs_error_incompatible_type") 9}) 10 11test_that("[<-.tbl_df supports subsetting with a logical matrix (#649)", { 12 foo <- tibble(x = 1:10, y = 1:10, z = letters[1:10]) 13 14 m <- matrix(c(rep(FALSE, 8), rep(TRUE, 3), rep(FALSE, 19)), ncol = 3) 15 foo[m] <- 1 16 expect_equal(foo[m], c(1, 1, 1)) 17 18 expect_error(foo[m] <- 1:3) 19 20 m <- matrix(c(rep(FALSE, 18), rep(TRUE, 3), rep(FALSE, 9)), ncol = 3) 21 expect_error(foo[m] <- 1, class = "tibble_error_assign_incompatible_type") 22}) 23