Skip to content

Commit a659bcd

Browse files
BUG FIX: Make future backend arguments (from the evaluator) available
to the backend factory function, so that things like: mybackend <- function(..., a = f(b), b = 0) { ... } works. Without this fix, 'b' will not be found.
1 parent d03e044 commit a659bcd

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future
2-
Version: 1.67.0-9007
2+
Version: 1.67.0-9008
33
Title: Unified Parallel and Distributed Processing in R for Everyone
44
Depends:
55
R (>= 3.2.0)

R/backend_api-01-FutureBackend-class.R

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -253,33 +253,34 @@ makeFutureBackend <- function(evaluator, ..., debug = FALSE) {
253253
## Apply future plan tweaks
254254
args <- attr(evaluator, "tweaks")
255255
if (is.null(args)) args <- list()
256-
257256
if (debug) {
258257
mdebugf("Evaluator tweak arguments: [n=%d]", length(args))
259258
mstr(args)
260259
}
261260

262261
args2 <- formals(evaluator)
263-
args2[["..."]] <- NULL
264-
args2$lazy <- NULL ## bc multisession; should be removed
265-
names2 <- names(args2)
266-
if ("envir" %in% names2) {
267-
args2[["envir"]] <- NULL
268-
names2 <- names(args2)
269-
}
262+
## Drop never-used arguments
263+
args2$`...` <- NULL
264+
args2$envir <- NULL # legacy
265+
args2$lazy <- NULL # bc multisession; should be removed
270266
if (debug) {
271267
mdebugf("Evaluator formal arguments: [n=%d]", length(args2))
272-
mstr(args)
273-
}
274-
for (name in names2) {
275-
args[[name]] <- args2[[name]]
268+
mstr(args2)
276269
}
277270

271+
## Merge tweaked arguments and future-backend evaluator arguments
272+
for (name in names(args2)) args[[name]] <- args2[[name]]
278273
if (debug) {
279-
mdebugf("Backend factory arguments: [n=%d]", length(args2))
280-
mstr(args2)
274+
mdebugf("Arguments passed to the future-backend factory: [n=%d]", length(args))
275+
mstr(args)
281276
}
282-
backend <- do.call(factory, args = args, envir = environment(factory))
277+
278+
## Make tweaked arguments and future-backend evaluator arguments
279+
## available when calling the factory function
280+
envir <- new.env(parent = environment(factory))
281+
for (name in names(args)) envir[[name]] <- args[[name]]
282+
283+
backend <- do.call(factory, args = args, envir = envir)
283284
if (debug) mdebugf("Backend: <%s>", commaq(class(backend)))
284285
stop_if_not(inherits(backend, "FutureBackend"))
285286

0 commit comments

Comments
 (0)