[Rd] Improving string concatenation

Joshua Bradley jgbradley1 at gmail.com
Wed Jun 17 20:24:08 CEST 2015


> 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, 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]]



More information about the R-devel mailing list