## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) # Enable densification for vignette examples old_options <- options(dbMatrix.allow_densify = TRUE) ## ----setup-------------------------------------------------------------------- library(dbMatrix) ## ----------------------------------------------------------------------------- # Create a sparse matrix set.seed(42) dgc <- Matrix::rsparsematrix(100, 50, density = 0.1, rand.x = function(n) rpois(n, 5) + 1) rownames(dgc) <- paste0("gene_", seq_len(100)) colnames(dgc) <- paste0("cell_", seq_len(50)) dplyr::glimpse(dgc) ## ----------------------------------------------------------------------------- # Note: by default the constructor creates a dbMatrix object in-memory con <- DBI::dbConnect(duckdb::duckdb(), ":memory:") dbsm <- dbMatrix( value = dgc, con = con, name = "test_matrix", class = "dbSparseMatrix", overwrite = TRUE ) # preview the object dbsm ## ----------------------------------------------------------------------------- dbsm + 1 dbsm * 100 ## ----------------------------------------------------------------------------- dbsm + dbsm ## ----------------------------------------------------------------------------- dbsm * dbsm ## ----------------------------------------------------------------------------- DBI::dbDisconnect(con, shutdown = TRUE) options(old_options) ## ----------------------------------------------------------------------------- sessionInfo()