[R] Evaluating lazily 'f<-' ?
Leonard Mada
|eo@m@d@ @end|ng |rom @yon|c@eu
Sun Sep 12 16:33:25 CEST 2021
How can I avoid evaluation?
right = function(x, val) {print("Right");};
padding = function(x) {print("Padding");};
df = data.frame(x=1:5, y = sample(1:5, 5));
### OK
'%=%' = function(x, val) {
x = substitute(x);
}
right(padding(df)) %=% 1; # but ugly
### Does NOT work
'right<-' = function(x, val) {
print("Already evaluated and also does not use 'val'");
x = substitute(x); # is evaluated before
}
right(padding(df)) = 1
Sincerely,
Leonard
More information about the R-help
mailing list