regex_funcs | R Documentation |
match_by_pattern()
tells whether row or column labels
match a regular expression.
Internally, grepl()
decides whether a match occurs.
replace_by_pattern()
replaces portions of row of column labels
when a regular expression is matched.
Internally, gsub()
performs the replacements.
match_by_pattern(
labels,
regex_pattern,
pieces = "all",
prepositions = RCLabels::prepositions_list,
notation = RCLabels::bracket_notation,
...
)
replace_by_pattern(
labels,
regex_pattern,
replacement,
pieces = "all",
prepositions = RCLabels::prepositions_list,
notation = RCLabels::bracket_notation,
...
)
labels |
The row and column labels to be modified. |
regex_pattern |
The regular expression pattern to determine matches and replacements.
Consider using |
pieces |
The pieces of row or column labels to be checked for matches or replacements. See details. |
prepositions |
A vector of strings that count as prepositions.
Default is |
notation |
The notation used in |
... |
Other arguments passed to |
replacement |
For |
By default (pieces = "all"
), complete labels (as strings) are checked for matches
and replacements.
If pieces == "pref"
or pieces == "suff"
,
only the prefix or the suffix is checked for matches and replacements.
Alternatively, pieces = "noun"
or pieces = <<preposition>>
indicate
that only specific pieces of labels are to be checked for matches and replacements.
When pieces = <<preposition>>
, only the object of <<preposition>>
is
checked for matches and replacement.
pieces
can be a vector, indicating multiple pieces to be checked for matches
and replacements.
But if any of the pieces
are "all", all pieces are checked and replaced.
If pieces
is "pref" or "suff", only one can be specified.
A logical vector of same length as labels
,
where TRUE
indicates a match was found and FALSE
indicates otherwise.
labels <- c("Production [of b in c]", "d [of Coal in f]", "g [of h in USA]")
# With default `pieces` argument, matching is done for whole labels.
match_by_pattern(labels, regex_pattern = "Production")
match_by_pattern(labels, regex_pattern = "Coal")
match_by_pattern(labels, regex_pattern = "USA")
# Check beginnings of labels
match_by_pattern(labels, regex_pattern = "^Production")
# Check at ends of labels: no match.
match_by_pattern(labels, regex_pattern = "Production$")
# Can match on nouns or prepositions.
match_by_pattern(labels, regex_pattern = "Production", pieces = "noun")
# Gives FALSE, because "Production" is a noun.
match_by_pattern(labels, regex_pattern = "Production", pieces = "in")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.