From hpages at fredhutch.org  Thu Jun 18 20:15:45 2015
From: hpages at fredhutch.org (=?windows-1252?Q?Herv=E9_Pag=E8s?=)
Date: Thu, 18 Jun 2015 11:15:45 -0700
Subject: [Rd] Improving string concatenation
In-Reply-To: <CAKShX4ACOn7Hnzo_pC+Ar9-r-8Gh3w4R77s7inNLyYto7Qoytg@mail.gmail.com>
References: <CAKShX4A5bVtxVAG+01QjNH0=LaVr6MH48xXs-OtbQQ2247cc_g@mail.gmail.com>	<CADwqtCMPAbayj7TENRPtPSXjyFi7wjWfdW9qke7n+PExdwkpbw@mail.gmail.com>	<CAKShX4D-LHgmh5cO2xxnLypzSgCWLDEnHopfE00MwbRFpRvmLg@mail.gmail.com>	<CAF8bMcZ1pRVVN2ZhDZ1EEq_vMN_1WzNvyw1e24cE=TDa=m+mmQ@mail.gmail.com>
	<CAKShX4ACOn7Hnzo_pC+Ar9-r-8Gh3w4R77s7inNLyYto7Qoytg@mail.gmail.com>
Message-ID: <55830AD1.4080300@fredhutch.org>

Hi Joshua,

On 06/17/2015 11:24 AM, Joshua Bradley wrote:
>> How would this new '+' deal with factors, as paste does or as the current
> '+'
>> does?  Would number+string and string+number cause errors (as in current
>> '+' in R and python) or coerce both to strings (as in current R:paste and
> in perl's '+').
>
>
> I had posted this sample code previously to demonstrate how string
> concatenation could be implemented
>
> "+" = function(x,y) {
>      if(is.character(x) & is.character(y)) {
>          return(paste0(x , y))
>      } else {
>          .Primitive("+")(x,y)
>      }}
>
>
> so it would only happen if both objects were characters,

Problem with this is that it's inconsistent with other binary operators
that will first coerce the non-character operand to character if the
other operand is a character.

H.

> otherwise you
> should expect the same behavior as before with all other classes. This
> would be backwards compatible as well since string+string was never
> supported before and therefore no one would have previously working code
> that could break.
>
> Josh Bradley
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Herv? Pag?s

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fredhutch.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



[Rd] Improving string concatenation
=?windows-1252?Q?Herv=E9_Pag=E8s?=