Re: [R] "a"+"b"

From: Prof Brian Ripley <>
Date: Tue 02 May 2006 - 21:03:22 EST

Not easily. There's a comment in ?Ops that for efficiency the group generics only dispatch on objects with a "class" attribute: otherwise you could use an S3 method like

`+.character` <- function(e1, e2) paste(e1,e2, sep="")

S4 methods are built on top of S3 methods as far as internal dispatch is concerned, so the same comment will apply there AFAICS.

I would think that the intention was also to positively discourage messing with the basics of R, as if you were able to do this erroneous uses would likely not get caught.

On Tue, 2 May 2006, Matthew Dowle wrote:

> Hi,
> Is there a way to define "+" so that "a"+"b" returns "ab" ?
>> setMethod("+",c("character","character"),paste)
> Error in setMethod("+", c("character", "character"), paste) :
> the method for function '+' and signature e1="character",
> e2="character" is sealed and cannot be re-defined
>> "a"+"b"
> Error in "a" + "b" : non-numeric argument to binary operator
> Thanks!
> [[alternative HTML version deleted]]
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Tue May 02 21:08:25 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 02 May 2006 - 22:09:57 EST.

Mailing list information is available at Please read the posting guide before posting to the list.