Skip to content
Prev 389127 / 398506 Next

Evaluating lazily 'f<-' ?

Hello,


I can include code for "padding<-"as well, but the error is before that, 
namely in 'right<-':

right = function(x, val) {print("Right");};
# more options:
padding = function(x, right, left, top, bottom) {print("Padding");};
'padding<-' = function(x, ...) {print("Padding = ");};
df = data.frame(x=1:5, y = sample(1:5, 5));


### Does NOT work
'right<-' = function(x, val) {
 ? ??? print("Already evaluated and also does not use 'val'");
 ? ??? x = substitute(x); # x was evaluated before
}

right(padding(df)) = 1;


I want to capture the assignment event inside "right<-" and then call 
the function padding() properly.

I haven't thought yet if I should use:

padding(x, right, left, ... other parameters);

or

padding(x, parameter) <- value;


It also depends if I can properly capture the unevaluated expression 
inside "right<-":

'right<-' = function(x, val) {

# x is automatically evaluated when using 'f<-'!

# but not when implementing as '%f%' = function(x, y);

}


Many thanks,


Leonard
On 9/13/2021 4:11 PM, Duncan Murdoch wrote: