Implements the %in% operator for dbMatrix objects. This operator checks if
elements from the left operand are contained in the right operand, returning
a logical vector.
Details
This is a method for the standard %in% operator for dbMatrix objects.
It follows R's standard behavior for the %in% operator:
When
xis a dbDenseMatrix, it returns a logical vector with the same length as the total number of elements in the matrix.When
tableis a dbDenseMatrix, it allows checking if elements inxare in the matrix.For dbSparseMatrix objects, it throws an error to match the behavior of dgCMatrix.
Examples
con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#> ℹ /tmp/RtmpQoK7i1/duckdb
#> This is removed when the R session ends.
#> • Extensions are re-downloaded each session.
#> • Secrets are lost.
#> ℹ Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#> ℹ Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#> ℹ See ?duckdb_storage for details and alternatives.
mat <- matrix(1:9, nrow = 3, ncol = 3)
dbmat <- dbMatrix(
value = mat,
con = con,
name = "example_matrix",
class = "dbDenseMatrix",
overwrite = TRUE
)
dbmat %in% c(1, 3, 5, 7, 9)
#> [1] TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
c(1, 3, 5, 7, 9) %in% dbmat
#> [1] TRUE TRUE TRUE TRUE TRUE
DBI::dbDisconnect(con, shutdown = TRUE)