From gmbecker at ucdavis.edu  Wed Jun 17 05:00:06 2015
From: gmbecker at ucdavis.edu (Gabriel Becker)
Date: Tue, 16 Jun 2015 20:00:06 -0700
Subject: [Rd] Improving string concatenation
In-Reply-To: <CAKShX4A5bVtxVAG+01QjNH0=LaVr6MH48xXs-OtbQQ2247cc_g@mail.gmail.com>
References: <CAKShX4A5bVtxVAG+01QjNH0=LaVr6MH48xXs-OtbQQ2247cc_g@mail.gmail.com>
Message-ID: <CADwqtCMPAbayj7TENRPtPSXjyFi7wjWfdW9qke7n+PExdwkpbw@mail.gmail.com>

On Jun 16, 2015 3:44 PM, "Joshua Bradley" <jgbradley1 at gmail.com> wrote:
>
> Hi, first time poster here. During my time using R, I have always found
> string concatenation to be (what I feel is) unnecessarily complicated by
> requiring the use of the paste() or similar commands.

I don't follow. In what sense is paste complicated to use? Not in the sense
of it's actual behavior, since what you propose below has identical
behavior. So is your objection simply the number of characters one must
type?

I would argue that having a separate verb makes code much more readable,
particularly at a quick glance. I know a character will come out of paste
no matter what goes in. That is not without value from a code maintenance
perspective. IMHO.

~G

>
>
> When searching for how to concatenate strings in R, several top search
> results show answers that say to write your own function or override the
> '+' operator.
>
> Sample code like the following from this
> <
http://stackoverflow.com/questions/4730551/making-a-string-concatenation-operator-in-r
>
> page
>
> "+" = function(x,y) {
>     if(is.character(x) & is.character(y)) {
>         return(paste(x , y, sep=""))
>     } else {
>         .Primitive("+")(x,y)
>     }}
>
>
>
> An old (2005) post
> <https://stat.ethz.ch/pipermail/r-help/2005-February/066709.html> on
r-help
> mentioned possible performance reasons as to why this type of string
> concatenation is not supported out of the box but did not go into detail.
> Can someone explain why such a basic task as this must be handled by
> paste() instead of just using the '+' operator directly? Would performance
> degrade much today if the '+' form of string concatenation were added into
> R by default?
>
>
>
> Josh Bradley
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

	[[alternative HTML version deleted]]



[Rd] Improving string concatenation
Gabriel Becker