Skip to content
Prev 389133 / 398506 Next

Evaluating lazily 'f<-' ?

R's parser doesn't work the way you're expecting it to. When doing an
assignment like:


padding(right(df)) <- 1


it is broken into small stages. The guide "R Language Definition" claims
that the above would be equivalent to:


`<-`(df, `padding<-`(df, value = `right<-`(padding(df), value = 1)))


but that is not correct, and you can tell by using `substitute` as you were
above. There isn't a way to do what you want with the syntax you provided,
you'll have to do something different. You could add a `which` argument to
each style function, and maybe put the code for `match.arg` in a separate
function:


match.which <- function (which)
match.arg(which, c("bottom", "left", "top", "right"), several.ok = TRUE)


padding <- function (x, which)
{
    which <- match.which(which)
    # more code
}


border <- function (x, which)
{
    which <- match.which(which)
    # more code
}


some_other_style <- function (x, which)
{
    which <- match.which(which)
    # more code
}


I hope this helps.
On Mon, Sep 13, 2021 at 12:17 PM Leonard Mada <leo.mada at syonic.eu> wrote: