This function is intended for use with the select_rows_byname and select_cols_byname functions. make_pattern correctly escapes special characters in row_col_names, such as ( and ), as needed. Thus, it is highly recommended that make_pattern be used when constructing patterns for row and column selections with select_rows_byname and select_cols_byname.

make_pattern(
  row_col_names,
  pattern_type = c("exact", "leading", "trailing", "anywhere")
)

Arguments

row_col_names

a vector of row and column names

pattern_type

one of exact, leading, trailing, or anywhere. Default is "exact".

Value

an extended regex pattern suitable for use with select_rows_byname or select_cols_byname.

Details

pattern_type controls the type of pattern created:

  • exact produces a pattern that selects row or column names by exact match.

  • leading produces a pattern that selects row or column names if the item in row_col_names matches the beginnings of row or column names.

  • trailing produces a pattern that selects row or column names if the item in row_col_names matches the ends of row or column names.

  • anywhere produces a pattern that selects row or column names if the item in row_col_names matches any substring of row or column names.

Examples

make_pattern(row_col_names = c("a", "b"), pattern_type = "exact")
#> [1] "^a$|^b$"