cat_magic_alias {stringmagic} | R Documentation |
Display messages using interpolated strings
Description
Utilities to display messages using string_magic
interpolation and operations to generate the message.
Usage
cat_magic_alias(
.sep = "",
.end = "",
.width = FALSE,
.leader = "",
.vectorize = FALSE,
.delim = c("{", "}"),
.last = NULL,
.collapse = NULL,
.trigger = TRUE,
.check = TRUE,
.namespace = NULL
)
message_magic_alias(
.sep = "",
.end = "\n",
.width = FALSE,
.leader = "",
.vectorize = FALSE,
.delim = c("{", "}"),
.last = NULL,
.collapse = NULL,
.trigger = TRUE,
.check = TRUE,
.namespace = NULL
)
cat_magic(
...,
.sep = "",
.end = "",
.width = FALSE,
.leader = "",
.envir = parent.frame(),
.vectorize = FALSE,
.delim = c("{", "}"),
.last = NULL,
.collapse = NULL,
.trigger = TRUE,
.check = TRUE,
.help = NULL,
.namespace = NULL
)
catma(
...,
.sep = "",
.end = "",
.width = FALSE,
.leader = "",
.envir = parent.frame(),
.vectorize = FALSE,
.delim = c("{", "}"),
.last = NULL,
.collapse = NULL,
.trigger = TRUE,
.check = TRUE,
.help = NULL,
.namespace = NULL
)
message_magic(
...,
.sep = "",
.end = "\n",
.width = NULL,
.leader = "",
.envir = parent.frame(),
.vectorize = FALSE,
.delim = c("{", "}"),
.last = NULL,
.collapse = NULL,
.trigger = TRUE,
.check = TRUE,
.help = NULL,
.namespace = NULL
)
mema(
...,
.sep = "",
.end = "\n",
.width = NULL,
.leader = "",
.envir = parent.frame(),
.vectorize = FALSE,
.delim = c("{", "}"),
.last = NULL,
.collapse = NULL,
.trigger = TRUE,
.check = TRUE,
.help = NULL,
.namespace = NULL
)
Arguments
.sep |
Character scalar, default is the empty string |
.end |
Character scalar, default is |
.width |
Can be 1) a positive integer, 2) a number in (0;1), 3)
Note that you can use the special variable |
.leader |
Character scalar, default is |
.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 |
.collapse |
Character scalar, default is |
.trigger |
Logical, default is |
.check |
Logical scalar, default is |
.namespace |
Character scalar or |
... |
Character scalars that will be collapsed with the argument To interpolate, you can
use Use the argument Note that in interpolations you have access to the special variables: |
.envir |
An environment used to evaluate the variables in |
.help |
Character scalar or |
Details
These functions are base::cat()
/message()
wrappers aroung string_magic()
. There is one notable difference
with respect to cat
/message
. It's the ability to add newlines after words for
the message to fit a target width. This is controlled with the argument .width
. This is
active by default for message_magic
(default is .width = NULL
which leads to the
minimum betwen 120 characters and 90% of the screen width).
You can very easily change the default values with the alias generators cat_magic_alias
and
message_magic_alias
.
[Advanced]
A note for package developers who would use these functions and
also use custom string_magic
operations created with string_magic_register_fun()
or
string_magic_register_ops()
. To ensure forward compatibility the new operations created
should be defined in the package namespace (see the ad hoc section in string_magic_register_fun()
help).
To access these operators in their specific namespaces, you must use an alias with
cat_magic_alias
or message_magic_alias
with the argument .namespace = "myPackageName"
(to avoid having to provide the .namespace
argument repeatedly).
Value
The functions cat_magic()
and message_magic()
do not return anything, they simply print on the console.
The function cat_magic_alis()
returns a function behaving identically to cat_magic()
but for which the
default values have been altered.
Same for message_magic_alias()
.
Functions
-
cat_magic_alias()
: Create an alias ofcat_magic
with custom defaults -
message_magic_alias()
: Create an alias ofmessage_magic
with custom defaults -
catma()
: Alias tocat_magic
-
message_magic()
: Display messages using interpolated strings -
mema()
: Alias tomessage_magic
See Also
Other tools with aliases:
string_clean_alias()
,
string_magic()
,
string_magic_alias()
,
string_ops_alias()
,
string_vec_alias()
Examples
start = Sys.time()
Sys.sleep(0.05)
message_magic("This example has run in {difftime ? start}.")
cat_magic("Let's write a very long message to illustrate how .width work.",
.width = 40)
# Let's add a leader
cat_magic("Let's write a very long message to illustrate how `.width` work.",
"And now we add `.leader`.", .width = 40, .leader = "#> ")
# newlines respect the introductory spaces
cat_magic("Here's a list:",
" + short item",
" + this is a very long item that likely overflows",
.width = 30, .sep = "\n")
#
# define custom defaults
#
# Unhappy about the default values? Create an alias!
# Here we change the defaults to mimic the printing of a column
cat_column = cat_magic_alias(.sep = "\n", .end = "\n", .vectorize = TRUE,
.last = "fill.center, ' + 'paste.both")
cat_column("code string_magic", "write the docs", "write the vignettes")