string_ops_alias {stringmagic} | R Documentation |
Chains basic operations to character vectors
Description
Simple tool to perform multiple operations to character vectors.
Usage
string_ops_alias(op = NULL, pre_unik = NULL, namespace = NULL)
string_ops(
x,
...,
op = NULL,
pre_unik = NULL,
namespace = NULL,
envir = parent.frame()
)
st_ops(
x,
...,
op = NULL,
pre_unik = NULL,
namespace = NULL,
envir = parent.frame()
)
Arguments
op |
Character vector or |
pre_unik |
Logical scalar, default is |
namespace |
Character scalar or If so pass the name of your package in this argument so that your function can access
the new |
x |
A character vector. If not a character vector but atomistic (i.e. not a list), it will be converted to a character vector. |
... |
Character scalars. Character scalar containing the comma separated values
of operations to perform to the vector. The 50+ operations are detailed in the help
page of |
envir |
Environment in which to evaluate the interpolations if the flag |
Details
This function is a simple wrapper around string_magic. Formally, string_ops(x, "op1, op2")
is equivalent to string_magic("{op1, op2 ? x}")
.
Value
In general it returns a character vector. It may be of a length different from the original one, depending on the operations performed.
Functions
-
string_ops_alias()
:string_ops
alias with custom defaults -
st_ops()
: Alias tostring_ops
Author(s)
Laurent R. Berge
See Also
Other tools with aliases:
cat_magic_alias()
,
string_clean_alias()
,
string_magic()
,
string_magic_alias()
,
string_vec_alias()
Examples
# data on car models
cars = row.names(mtcars)
# let's get the brands starting with an "m"
string_ops(cars, "'i/^m'get, x, unik")
# Explainer:
# 'i/^m'get: keeps only the elements starting with an m,
# i/ is the 'regex-flag' "ignore" to ignore the case
# ^m means "starts with an m" in regex language
# x: extracts the first pattern. The default pattern is "[[:alnum:]]+"
# which means an alpha-numeric word
# unik: applies unique() to the vector
# => see help in ?string_magic for more details on the operations
# let's get the 3 largest numbers appearing in the car models
string_ops(cars, "'\\d+'x, rm, unik, num, dsort, 3 first")
# Explainer:
# '\d+'x: extracts the first pattern, the pattern meaning "a succession"
# of digits in regex language
# rm: removes elements equal to the empty string (default behavior)
# unik: applies unique() to the vector
# num: converts to numeric
# dsort: sorts in decreasing order
# 3 first: keeps only the first three elements
# You can use several character vectors as operations:
string_ops(cars,
"'\\d+'x, rm, unik",
"num, dsort, 3 first")