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