Skip to content
Prev 8296 / 12125 Next

[R-pkg-devel] Using function with same name as argument as default argument

Hello,


This isn't something that can be fixed in the parser. If an argument isn't
provided, its default value is evaluated inside the function, so it gives
you a loop where schema = schema(x), but then what's schema, it's
schema(x), thus the recursion error. you could do something like this:

foo <- function (x, schema = schema(x))
{
    if (missing(schema)) {
        rm(schema)
        schema <- schema(x)
    }
}

which, while kinda gross looking, means that schema = schema(x) can be
evaluated without causing a recursion error.
On Mon, Aug 8, 2022, 09:11 Jan van der Laan <rhelp at eoos.dds.nl> wrote: