Is there a package that would extend the + operator with method for character types ( i.e. `+.character` <-function(x,y) {...} )?
In base R, writing this yields error:
"a" + "b" # Error in "a" + "b" : non-numeric argument to binary operator What I would like to achieve is:
"a" + "b" #"ab" I am aware of paste0("a","b"), but "a" + "b" is arguably more readable/shorter.
Of course there is always possibility to define special binary operator:
`%+%` <- function(x,y) paste0(x,y) "foo" %+% "bar" %+% "baz" # "foobarbaz"
characteris a special class (it's also a type). It looks like+is hardcoded to give this error for character input and never calls the method in such a case.