stringmagicis now fully compatible with R v3.5.0 (at least)
-
fix major bug in the if-else operator (
&) leading to opposite operations -
in
string_vec, fix bug leading to the removal of empty strings -
in
string_vec, fix bugs with the arguments.sepand.collapse -
in C code: use
STRING_PTR_ROinstead ofSTRING_PTRto comply with new CRAN policy
string_magic: new operatortableto flexibly attach elements with their frequencies:
dna = string_split("atagggagctacctgcgcgtcgcccaaaagcaggg", "")
cat_magic("Letters in the DNA seq. {''c, Q ? dna}: ",
# by default: inverse frequency sorting
" - default: {table, enum ? dna}",
" - value sorted: {table.sort, enum ? dna}",
# argument in single quotes to customize the display, it's a
# `string_magic` interpolation
" - shares: {'{x} [{round(s * 100)}%]' table, enum ? dna}",
# `fsort` sorts by **increasing** frequency
" - freq. sorted: {'{q ? x}' table.fsort, enum ? dna}",
.sep = "\n")
#> Letters in the DNA seq. "atagggagctacctgcgcgtcgcccaaaagcaggg":
#> - default: g (12), c (10), a (9) and t (4)
#> - value sorted: a (9), c (10), g (12) and t (4)
#> - shares: g [34%], c [29%], a [26%] and t [11%]
#> - freq. sorted: 't', 'a', 'c' and 'g'string_magic: new operatorsroundandsignif(wtih shorthandsr0tor6ands0tos6) to flexibly format numbers:
x = c(153, 207.256, 0.00254, 15231312.2)
# keeping one significant digit
cat_magic("v1: {s1, align ? x} ",
# removing the comma for large numbers and preserving ints
"v2: {s1.int.nocomma ? x}", .collapse = "\n")
#> v1: 153.0 v2: 153
#> v1: 207.2 v2: 207.2
#> v1: 0.002 v2: 0.002
#> v1: 15,231,312.2 v2: 15231312.2
string_magic("pi = {r3 ? pi}")
#> [1] "pi = 3.142"-
add the argument
.datatostring_magic(), used to evaluate variables in the interpolations -
new functions
get_interpolated_expr()andget_interpolated_vars(). This function recovers all the expressions to be interpolated in a call tostring_magic()(oriented for developers). -
new argument
center.rightin the functionstring_fillto resolve situations in which the characters are not perfectly centered -
make
cat_magicandmessage_magicmore in line with their base R counterparts (they work properly with vectors now)
- the functions
st_ops,st_is,st_any,st_allhave been renamed intostops,stis,stany,stallto align with the convention of all other aliases. Although the names aren't great, at least they are consistent.
-
the new operator
swidth(screen width) replaces the operatorwidth. The operator width becomes an alias forfill. -
the default screen width for
message_magicbecomes the minimum between 100 characters and 90% of the current screen size (actually the console size). -
rework the argument
.widthinmessage_magicandcat_magic: now the special variable.swcan only be used in a one-sided formula (non-standard evaluation is still supported for retro-compatibility) -
improve error handling
-
add
leftoption to operators when relevant. Thanks to @kylebutts, #3 -
in
string_vec, change the default of argument.protect.varstoFALSE, which is much more aligned to common sense -
in
string_magic's argument.post: removal of argument catching, which could lead, occasionnally, to bugs very hard to understand -
in
string_vec: add the arguments.checkand.help.
- make
stringmagiccompatible withRin [4.1.0; 4.1.2].
- add argument
.triggertocat/message_magic_alias
- make
stringmagiccompatible withR< 4.1.0 by removing calls to...names().
-
add
string_extractto extract patterns -
add
string_splitto split character strings
-
string_opsnow uses...to pass operations. This is backward compatible. -
string_clean: now the magic flag also expands the replacements:
x = "Hi Mary, how's John doing?"
from = "John"
to = "Kate"
string_clean(x, "m/{from} => {to}")
#> [1] "Hi Mary, how's Kate doing?"-
string_magic: add thecommaflag to theenumoperation. In that case, the enumeration ends with ", " instead of ", and ". -
string_magic: the if-else operation&now keeps memory of variables accessed within data sets:
data = list(x = c(15, 25, 550), y = rnorm(1000))
string_magic("The values are{& length(data$x) < 5 ; : {enum ? .} ; too many}.")
# [1] "The values are: 15, 25 and 550."
string_magic("The values are{& length(data$y) < 5 ; : {enum ? .} ; too many}.")
# [1] "The values are too many."-
string_magic: new operationdeparse(alias:dp) to deparse an object and keep only the first characters of the deparsed string. -
improve error messages.
- new battery of short aliases:
smaforstring_magic,catmafor catmagic,memaformessage_magic, etc.. (st_ops,st_is,st_any,st_all,stextract,stwhich,stget,stclean,stvec,streplace,stsplit-- short names with vowels aftersthave an underscore.)
First public release. The syntax should be stable.
This package is a spinoff from fixest's formula syntax interpolation.
Many thanks to Achim Zeileis, Vincent Arel-Bundock and Kyle Butts who provided insightful comments during the development.