Skip to contents

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.

Usage

# S4 method for class 'dbDenseMatrix,ANY'
x %in% table

# S4 method for class 'ANY,dbDenseMatrix'
x %in% table

# S4 method for class 'dbSparseMatrix,ANY'
x %in% table

Arguments

x

A dbMatrix object or any other object

table

Any object or a dbMatrix object

Value

A logical vector of the same length as x, indicating which elements of x are in table.

Details

This is a method for the standard %in% operator for dbMatrix objects. It follows R's standard behavior for the %in% operator:

  • When x is a dbDenseMatrix, it returns a logical vector with the same length as the total number of elements in the matrix.

  • When table is a dbDenseMatrix, it allows checking if elements in x are 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)