Make sure that a matrix contains rows and columns of the given names in the given order.
Arguments
- x
A matrix
- row_names
character vector of row names
- col_names
character vector of column names
- fill_value
value to fill a row or column with if a row or column does not exist in
x
Examples
m <- matrix(1:12, nrow = 3, ncol = 4, dimnames = list(
rows = paste0("row", 1:3), cols = paste0("col", 1:4)
))
# Add two rows, reverse order of rows, add one column, remove one column
assertRowsAndColumns(
m,
row_names = paste0("row", 4:0),
col_names = paste0("col", 0:2)
)
#> cols
#> rows col0 col1 col2
#> row4 0 0 0
#> row3 0 3 6
#> row2 0 2 5
#> row1 0 1 4
#> row0 0 0 0