[Rd] string concatenation operator (revisited)

Radford Neal r@d|ord @end|ng |rom c@@toronto@edu
Mon Dec 6 07:14:02 CET 2021

> The TL;DR version is base R support for a `+.character` method. This
> would essentially provide a shortcut to `paste0`...

In pqR (see pqR-project.org), I have implemented ! and !! as binary
string concatenation operators, equivalent to paste0 and paste,

For instance,

    > "hello" ! "world"
    [1] "helloworld"
    > "hello" !! "world"
    [1] "hello world"
    > "hello" !! 1:4
    [1] "hello 1" "hello 2" "hello 3" "hello 4"
This seems preferable to overloading the + operator, which would lead
to people reading code wondering whether a+b is doing an addition or a
string concatenation.  There are very few circumstances in which one
would want to write code where a+b might be either of these.  So it's
better to make clear what is going on by having a different operator
for string concatenation.  

Plus ! and !! semm natural for representing paste0 and paste, whereas
using ++ for paste (with + for paste0) would look rather strange.

   Radford Neal

More information about the R-devel mailing list