0

Since I have to use paste function heavily in practice, I wonder whether we can use a specific sign or operator like "+"or "++" to connect strings like in Python.

So we can have

con = "a" + "b"

then con becomes "a b" or "ab".

And would there be any side effects if we do so?

John
  • 1,647
  • 1
  • 20
  • 46

1 Answers1

1

You need to overwrite "+" operation but this is not a recommend method.

A very quick implementation as below. More general, you need to handle different inputs in the function and return the original "+" when the inputs are not strings.

"+" <- function(a, b) {
  paste(a, b)
}
> "12" + "34"
[1] "12 34"
Patric
  • 1,923
  • 16
  • 18