I wrote a binary operator function for R (i.e. one with a name like %X% so that instead of having to type %X%(a,b) I can use the more convenient syntax a %X% b. My goal is to have a wrapper for <- that does things like log what was done to objects in that environment and check for a 'protected' attribute which would warn the user before overwriting that object.
All of this works, except that if I try do do something like a %X% b + c inside the function all you see is a %X% b _and that is also all it does; a gets assigned the value of b and c is completely ignored. a %X% (b + c) works and so does %X%(a, b + c) but the whole point of writing this as a binary operator is to avoid parentheses.
If I overwrite <-, its sys.call() sees everything to the left and right of it. Why does mine only see only the adjacent names from the command line?
Here is code that replicates this problem:
`%X%` <- function(...){
print(deparse(sys.call()));
}
a %X% 3 + 1:10;
The desired result is "a %X% 3 + 1:10" The observed result is "a %X% 3"
Thanks.