rename_to_pref_suff_byname: Rename matrix rows and columns by prefix and suffix

View source: R/Utilities.R

rename_to_pref_suff_bynameR Documentation

Rename matrix rows and columns by prefix and suffix

Description

[Superseded] It can be convenient to rename rows or columns of matrices based on retaining prefixes or suffixes. This function provides that capability.

Usage

rename_to_pref_suff_byname(a, keep, margin = c(1, 2), notation)

Arguments

a

a matrix or list of matrices whose rows or columns will be renamed.

keep

one of "prefix" or "suffix" indicating which part of the row or column name to retain.

margin

one of 1, 2, or c(1, 2) where 1 indicates rows and 2 indicates columns.

notation

See notation_vec().

Details

A prefix is defined by an opening string (prefix_open) and a closing string (prefix_close). A suffix is defined by an opening string (suffix_open) and a closing string (suffix_close). If sep is provided and none of prefix_open, prefix_close, suffix_open, and suffix_close are provided, default arguments become: * prefix_open: "", * prefix_close: sep, * suffix_open: sep, and * suffix_close: "".

The keep parameter tells which portion to retain (prefixes or suffixes),

If prefixes or suffixes are not found in a row and/or column name, that name is unchanged.

Value

a with potentially different row or column names.

Examples

# This function is superseded. 
# Instead, use `rename_to_pieces_byname()`.
# For example:
m <- matrix(c(1, 2, 
              3, 4, 
              5, 6), nrow = 3, byrow = TRUE, 
            dimnames = list(c("a -> b", "r2", "r3"), c("a -> b", "c -> d")))
m
rename_to_piece_byname(m, piece = "pref", notation = RCLabels::arrow_notation)
# Note, labels are lost, because some labels are missing a suffix.
rename_to_piece_byname(m, piece = "suff", notation = RCLabels::arrow_notation)
# Original documentation:
rename_to_pref_suff_byname(m, keep = "pref", notation = RCLabels::arrow_notation)
rename_to_pref_suff_byname(m, keep = "suff", notation = RCLabels::arrow_notation)

MatthewHeun/byname documentation built on Feb. 17, 2024, 4:51 p.m.