Skip to content

option to force evaluation of supplied function in partial to avoid infinite recursion #387

@t-kalinowski

Description

@t-kalinowski

Hello,

This makes an infinite recursive loop

f <- function(a = "a", b = "b") format(as.list(environment()))
f <- partial(f, b = "c")
f()

It would be nice to be able to force f inside of partial to avoid this. Something like:

partial2 <- function(fun, ..., .lazy = FALSE) {
  new_args <- if (.lazy)
    eval(substitute(alist(...)))
  else
    list(...)
  formals(fun) <- modifyList(formals(fun), new_args, TRUE)
  fun
}


f <- function(a = "a", b = "b") as.list(environment())
f <- partial2(f, b = "c")
f()

Metadata

Metadata

Assignees

No one assigned

    Labels

    adverb 📚bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions