validation-matrix_dimensions: Validation functions for the dimensions of matrix-like...

validation-matrix_dimensionsR Documentation

Validation functions for the dimensions of matrix-like objects

Description

Functions to check whether a matrix-like object has expected dimension numbers or names.

Usage

validMatDims(mat, nrow = NULL, ncol = NULL)

validMatDimnames(
  mat,
  row.names = NULL,
  col.names = NULL,
  dup.rownames = FALSE,
  dup.colnames = FALSE
)

Arguments

mat

A matrix-like object

nrow

Expect how many rows in 'mat'.

ncol

Expect how many columns in 'mat'.

row.names

Expected row names for 'mat'.

col.names

Expected column names for 'mat'.

dup.rownames, dup.colnames

Whether or not to allow duplicated dimension names in 'mat'.

Value

If all the validations are passed, return invisible 'NULL'.

Examples

mat1 <- matrix(0, 3, 5)
validMatDims(mat1, 3, 5)

## Check dimnames
mat1 <- matrix(0, 3, 5)
rownames(mat1) <- letters[1:3]
colnames(mat1) <- LETTERS[1:5]
try(validMatDimnames(mat1, row.names = letters[2:4]))  ## Error
rownames(mat1) <- c("A", "B", "A")
try(validMatDimnames(mat1, row.names = letters[2:4]))  ## Error


easy.utils documentation built on April 4, 2025, 6:13 a.m.