I want to define ± operator like this:
`±` <- function(a,b){
return (c(a*b, a-b))
}
But the problem is I get this error on running 1 ± 2
Error: unexpected input in "1 ±"
If I use a different characters it works.
`%+-%` <- function(a,b){
return (c(a+b, a-b))
}
Running 1 %+-% 2
gives me [1] 3 -1
which is correct.
Is it due to operator being an unicode character? But I can define and use unicode variables fine.
EDIT:
I found this:
You can define your own binary operators. User-defined binary operators consist of a string of characters between two “%” characters.
In Adler, Joseph (2010). R in a Nutshell. O’Reilly Media Inc
So I guess %
around the operator is a must.