string_magic_alias {stringmagic} | R Documentation |
Create string_magic
aliases with custom defaults
Description
Utility to easily create string_magic
aliases with custom default
Usage
string_magic_alias(
.sep = "",
.vectorize = FALSE,
.delim = c("{", "}"),
.last = NULL,
.post = NULL,
.default = NULL,
.nest = FALSE,
.invisible = FALSE,
.local_ops = NULL,
.collapse = NULL,
.check = TRUE,
.class = NULL,
.namespace = NULL
)
Arguments
.sep |
Character scalar, default is the empty string |
.vectorize |
Logical scalar, default is |
.delim |
Character vector of length 1 or 2. Default is If of length 1, it must be of the form: 1) the opening delimiter,
2) a single space, 3) the closing delimiter. Ex: [ ]: R:%20 [", "]: R:%22,%20%22 |
.last |
Character scalar, a function, or |
.post |
Function or |
.default |
Character scalar or |
.nest |
Logical, default is |
.invisible |
Logical scalar, default is |
.local_ops |
Named list or |
.collapse |
Character scalar, default is |
.check |
Logical scalar, default is |
.class |
Character vector representing the class to give to the object returned.
By default it is |
.namespace |
Character scalar or |
Details
Use this function if you want to change string_magic
default values. For example,
if you want the interpolation to be done with "{{}}"
(instead of {}
) or if you want the
default separation to be the space (instead of the empty string). See the example.
Value
This function returns a function which will behave in the same way as string_magic()
Writing a package using string_magic
If you want to use string_magic
in your package and want to make use of custom operations:
place any
string_magic_register_fun
andstring_magic_register_ops
in your.onLoad
function (seehelp("onLoad")
). The .onLoad function is run whenever the package is loaded for the first time. It's a function that you can place anywhere in yourR/*
files and which looks like this:
.onLoad = function(libname, pkgname){ # string_magic custom operations string_magic_register_ops("'80|-'fill", "h1") invisible() }
if you don't want to place the
string_magic_register_*
functions in the .onLoad function, you can, but then you must provide the argumentnamespace
:
string_magic_register_ops("'80|-'fill", "h1", namespace = "myPackageName")
you must create an
string_magic_alias()
to create an alias tostring_magic()
and use the argument.namespace = "myPackageName"
. Use this opportunity to change the defaults if you wish. You can even override thestring_magic
function:
# creating an alias with the same name + changing the delimiter string_magic = stringmagic::string_magic_alias(.namespace = "myPackageName", .delim = "{{ }}")
Author(s)
Laurent Berge
See Also
Other related to string_magic:
string_magic_register_fun()
Other tools with aliases:
cat_magic_alias()
,
string_clean_alias()
,
string_magic()
,
string_ops_alias()
,
string_vec_alias()
Examples
# we create the function sma2 with different defaults
sma2 = string_magic_alias(.delim = ".[ ]", .sep = " ", .class = "string_magic")
person = "john doe"
sma2("Hello", ".[title ? person]")
# you can use the arguments whose default has been changed
sma2("Hello", ".[title ? person]", .sep = ": ")