-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
option to force evaluation of supplied function in partial to avoid infinite recursion #387
Comments
Also it would be nice if functions returned by f <- function(a = "a", b = "b") format(as.list(environment()))
f2 <- purrr::partial(f, b = "c")
f2()
#> a b
#> "a" "c"
f2(b = "user supplied value")
#> Error in f(b = "c", ...): formal argument "b" matched by multiple actual arguments
f3 <- partial2(f, b = "c")
f3(b = "user supplied value")
#> a b
#> "a" "user supplied value" |
@t-kalinowski Could this be a duplicate of #349? (Your first concern is addressed there.) Your second suggestion could be convenient. If it were allowed, however, then |
Hi @egnha, thanks for taking a look. I don't think it's a duplicate, because it's possible to address one without addressing the other. Regarding the usage of However, I think these are mostly questions of interface design. An implementation that incorporates the two ideas above, places new arguments in partial3 <- function(fun, ..., .lazy = FALSE) {
partially_supplied_args <- if (.lazy)
eval(substitute(alist(...)))
else
list(...)
force(fun)
function(...) {
args <- modifyList( partially_supplied_args, eval(substitute(alist(...))), TRUE )
eval(as.call(c(fun, args)))
}
}
f <- function(a = "a", b = "b") {
if (missing(b))
paste("b was missing, its value is:", b)
else
paste("b was not missing, its value is:", b)
}
f()
#> [1] "b was missing, its value is: b"
f2 <- purrr::partial(f, b = "c")
f2()
#> [1] "b was not missing, its value is: c"
f <- partial3(f, b = "c")
f()
#> [1] "b was not missing, its value is: c"
f(b = "z")
#> [1] "b was not missing, its value is: z" But, this still doesn't address #349
|
Hello,
This makes an infinite recursive loop
It would be nice to be able to force
f
inside of partial to avoid this. Something like:The text was updated successfully, but these errors were encountered: