Read a subset of columns from the data matrix

rcpp_mmutil_read_columns(
  mtx_file,
  memory_location,
  r_column_index,
  verbose = FALSE,
  NUM_THREADS = 1L,
  MIN_SIZE = 10L
)

Arguments

mtx_file

data file

memory_location

column -> memory location

r_column_index

column indexes to retrieve (1-based)

Value

a dense sub-matrix

Examples


rr <- rgamma(100, 1, 1) # one hundred cells
mm <- matrix(rgamma(10 * 3, 1, 1), 10, 3)
data.hdr <- "test_sim"
.files <- mmutilR::rcpp_mmutil_simulate_poisson(mm, rr, data.hdr)
data.file <- .files$mtx
idx.file <- .files$idx
mtx.idx <- mmutilR::rcpp_mmutil_read_index(idx.file)
Y <- as.matrix(Matrix::readMM(data.file))
col.pos <- c(1,13,77) # 1-based
yy <- mmutilR::rcpp_mmutil_read_columns(
                 data.file, mtx.idx, col.pos)
all(Y[, col.pos, drop = FALSE] == yy)
#> [1] TRUE
print(head(Y[, col.pos, drop = FALSE]))
#>      [,1] [,2] [,3]
#> [1,]    0    6    1
#> [2,]    0    3    0
#> [3,]    1    1    1
#> [4,]    0    2    0
#> [5,]    1    6    1
#> [6,]    0    7    1
print(head(yy))
#>      [,1] [,2] [,3]
#> [1,]    0    6    1
#> [2,]    0    3    0
#> [3,]    1    1    1
#> [4,]    0    2    0
#> [5,]    1    6    1
#> [6,]    0    7    1
unlink(list.files(pattern = data.hdr))