[Rd] Improving string concatenation

Joshua Bradley jgbradley1 at gmail.com
Wed Jun 17 00:32:55 CEST 2015

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.

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

"+" = function(x,y) {
    if(is.character(x) & is.character(y)) {
        return(paste(x , y, sep=""))
    } else {

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

More information about the R-devel mailing list