I've seen some packages that defines new classes and binary operators like +
or -
still work. There must be a way to define how +
operates according to the class of the two arguments, in a way like defining
plot.myclass = function(x) something
changes what plot()
does if the argument is of class myclass
.
How can I change what a built-in binary operator does? Do they work exactly like S3 methods?
As an example, let's say I want to have an addition operator for character
objects, so that
"abc" + "def"
returns "abcdef"
, how to specify that I want +
to return paste(arg1,arg2)
when the arguments are character objects.