tests/testthat/test_matrix.R

# Tests for matrix checks

data("pbmc_small")

pbmc_small <- suppressWarnings(suppressMessages(UpdateSeuratObject(pbmc_small)))

counts <- GetAssayData(pbmc_small, assay = "RNA", slot = "counts")

test_that("CheckMatrix works for valid matrix", {
  expect_null(CheckMatrix(counts))
})

test_that("CheckMatrix warns for non-integer counts", {
  counts[1,1] <- 1/2
  expect_warning(CheckMatrix(counts))
})

test_that("CheckMatrix warns for NA values", {
  counts[1,1] <- NA
  expect_warning(CheckMatrix(counts))
})

test_that("CheckMatrix warns for NaN values", {
  counts[1,1] <- NaN
  expect_warning(CheckMatrix(counts))
})

test_that("CheckMatrix warns for logical values", {
  counts <- as(object = counts, Class = "lsparseMatrix")
  expect_warning(CheckMatrix(counts))
})

Try the SeuratObject package in your browser

Any scripts or data that you put into this service are public.

SeuratObject documentation built on June 8, 2025, 10:10 a.m.