"+" を文字列連結演算子とする場合
"+" = function(e1, e2) {
if (is.numeric(e1) && is.numeric(e2)) {
base::"+"(e1, e2)
} else {
paste0(e1, e2)
}
}
> "abc" + "12345" + "あいうえお"
[1] "abc12345あいうえお"
> 123456 + "numeric"
[1] "123456numeric"
> 456 + 100
[1] 556
> 456L + 100L
[1] 556
> 456 + 0
[1] 456
> TRUE + FALSE
[1] "TRUEFALSE"
> "123" + TRUE + "asd"
[1] "123TRUEasd"
> (1 == 1) + (2 != 3)
[1] "TRUETRUE"