affix | R Documentation |
A set of helper functions for adding or removing specific prefixes and/or suffixes to character vectors. This is useful for formatting strings in mathematical, XML, or other structured text contexts.
affix()
– Add any prefix and/or suffix to each element of a character vector; alias: add_affix()
.
math()
– Add a dollar sign ($
) to both ends of each element (LaTeX-style math); aliases: add_math()
, lmath()
.
bracket()
– Wrap each element in parentheses; aliases: add_bracket()
, brkt()
.
cdata()
– Wrap each element in <![CDATA[ ... ]]>
(XML CDATA section); alias: add_cdata()
.
unaffix()
– Remove a given prefix and/or suffix from each element; alias: remove_affix()
.
unquote()
– Remove surrounding double quotes from each element; alias: remove_quotes()
.
uncdata()
– Remove a surrounding CDATA section from each element.; alias: remove_cdata()
.
affix(txt, prefix = "", suffix = "")
math(txt)
bracket(txt)
unaffix(txt, prefix = "", suffix = "")
unquote(txt)
uncdata(txt)
cdata(txt)
add_affix(txt, prefix = "", suffix = "")
add_cdata(txt)
add_math(txt)
lmath(txt)
add_bracket(txt)
brkt(txt)
remove_affix(txt, prefix = "", suffix = "")
remove_quotes(txt)
remove_cdata(txt)
txt |
|
prefix |
|
suffix |
|
A modified character
vector of the same length as txt
.
x <- c("alpha", "beta", "gamma")
# Add a prefix and suffix
affix(x, "[", "]")
#> [1] "[alpha]" "[beta]" "[gamma]"
# Wrap with LaTeX math delimiters
math(x)
#> [1] "$alpha$" "$beta$" "$gamma$"
# Remove quotes
quoted <- c('"a"', '"b"')
unquote(quoted)
#> [1] "a" "b"
# Wrap and unwrap CDATA
cdata_x <- cdata("text")
uncdata(cdata_x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.