modify_label_pieces: Modify pieces of row and column labels

View source: R/setters.R

modify_label_piecesR Documentation

Modify pieces of row and column labels

Description

Typical pieces include "noun" or a preposition, such as "in" or "from". See RCLabels::prepositions for additional examples. This argument may be a single string or a character vector.

Usage

modify_label_pieces(
  labels,
  piece,
  mod_map,
  prepositions = RCLabels::prepositions_list,
  inf_notation = TRUE,
  notation = RCLabels::bracket_notation,
  choose_most_specific = FALSE
)

Arguments

labels

A vector of row or column labels in which pieces will be modified.

piece

The piece (or pieces) of the row or column label that will be modified.

mod_map

A modification map. See details.

prepositions

A list of prepositions, used to detect prepositional phrases. Default is RCLabels::prepositions_list.

inf_notation

A boolean that tells whether to infer notation for x. Default is TRUE. See infer_notation() for details.

notation

The notation type to be used when extracting prepositions. Default is RCLabels::notations_list, meaning that the notation is inferred using infer_notation().

choose_most_specific

A boolean that tells whether the most specific notation is selected when more than one notation match. Default is FALSE.

Details

This function modifies pieces of row and column labels according to label_map that defines "one or many to one" relationships. This function is useful for aggregations. For example, replacing nouns can be done by ⁠modify_label_pieces(labels, piece = "noun", label_map = list(new_noun = c("a", "b", "c"))⁠. The string "new_noun" will replace any of "a", "b", or "c" when they appear as nouns in a row or column label. See examples for details.

The mod_map argument should consist of a named list of character vectors in which names indicate strings to be inserted and values indicate values that should be replaced. The sense is new = old or new = olds, where "new" is the new name (the replacement) and "old"/"olds" is/are a string/vector of strings, any one of which will be replaced by "new".

Note piece can be "pref"/"suff" or "noun"/"prepositions" If any piece is "pref" or "suff", all pieces are assumed to be a prefix or a suffix. If non of the pieces are "pref" or "suff", all pieces are assumed to be nouns or prepositions, such as "in" or "from". See RCLabels::prepositions for additional examples. This argument may be a single string or a character vector.

Value

labels with replacements according to piece and mod_map.

Examples

# Simple case
modify_label_pieces("a [of b in c]",
                    piece = "noun",
                    mod_map = list(new_noun = c("a", "b")))
# Works with a vector or list of labels
modify_label_pieces(c("a [of b in c]", "d [-> e in f]"),
                    piece = "noun",
                    mod_map = list(new_noun = c("d", "e")))
# Works with multiple items in the mod_map
modify_label_pieces(c("a [of b in c]", "d [-> e in f]"),
                    piece = "noun",
                    mod_map = list(new_noun1 = c("a", "b", "c"),
                                   new_noun2 = c("d", "e", "f")))
# Works with multiple pieces to be modified
modify_label_pieces(c("a [of b in c]", "d [-> e in f]"),
                    piece = c("noun", "in"),
                    mod_map = list(new_noun = c("a", "b", "c"),
                                   new_in   = c("c", "f")))

RCLabels documentation built on April 25, 2023, 5:11 p.m.