[Rd] "+" operator on characters revisited

Vitalie S. spinuvit.list at gmail.com
Sun Jan 23 12:56:50 CET 2011


Gabor Grothendieck <ggrothendieck at gmail.com> writes:

> On Sat, Jan 22, 2011 at 3:08 PM, Vitalie S. <spinuvit.list at gmail.com> wrote:
>>
>> Hello everyone!
>>
>> Motivated by the recent post on SO
>>
> http://stackoverflow.com/questions/4730551/making-a-string-concatenation-operator-in-r>
>> I wonder what is the current state of argument on making "+" to
>> concatenate character vectors. The "+" method is still sealed for
>> signature("character", "character") in the current version of R.
>>
>> The 4 years old R-devel thread
>> https://www.stat.math.ethz.ch/pipermail/r-devel/2006-August/038991.html>
>> on the same topic, stopped without reaching any definite conclusion.
>>
>> The only definite argument occurred in the thread against "+" operator
>> was the lack of commutativity (as if one have to prove algebraic
>> theorems in R).
>>
>> Yet another useful suggestion of introducing cat0() and paste0(), for
>> the common use of cat and paste with sep="" was not absorbed by the
>> core R either.
>
> The gsubfn package has always had a paste0 function and I would be
> happy to remove it if the core adds it.
>
> Also the gsubfn supports quasi perl style string interpolation that
> can sometimes be used to avoid the use of paste in the first place.
> Just preface the function in question by fn$ like this:
>
> library(gsubfn)
> fn$cat("pi = $pi\n")

Thanks for the tip. Not bad indeed.
Almost as readable as

cat("pi = " + pi + "\n")



More information about the R-devel mailing list