From a7b98353ed4adbb25c769d435cd2134c92d42913 Mon Sep 17 00:00:00 2001 From: Henrik Bengtsson Date: Sun, 8 May 2022 00:57:34 -0700 Subject: [PATCH] BUG FIX: S4 methods defined locally, that is, not in a package, failed to be found in sequential and multicore futures since future 1.22.0 [#615] --- DESCRIPTION | 2 +- NEWS | 5 ++++- R/globals.R | 2 +- tests/globals,S4methods.R | 3 --- tests/globals,locals.R | 11 ++--------- 5 files changed, 8 insertions(+), 15 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 66fab50f..dcf798a8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: future -Version: 1.25.0-9015 +Version: 1.25.0-9016 Title: Unified Parallel and Distributed Processing in R for Everyone Imports: digest, diff --git a/NEWS b/NEWS index c3d83f27..e7736dfb 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,7 @@ Package: future =============== -Version: 1.25.0-9015 [2022-05-07] +Version: 1.25.0-9016 [2022-05-08] SIGNIFICANT CHANGES: @@ -45,6 +45,9 @@ BUG FIXES: setalloccol(ans) : verbose must be TRUE or FALSE". See above 'SIGNIFICANT CHANGES' for how this was fixed. + * S4 methods defined locally, that is, not in a package, failed to be + found in sequential and multicore futures since future 1.22.0. + * The deprecation warning for using local = FALSE was silenced for sequential futures since future 1.25.0. diff --git a/R/globals.R b/R/globals.R index 9777e3cb..e033b6b0 100644 --- a/R/globals.R +++ b/R/globals.R @@ -387,7 +387,7 @@ getGlobalsAndPackages <- function(expr, envir = parent.frame(), tweak = tweakExp pkgs <- pkgs[isAttached] } - keepWhere <- getOption("future.globals.keepWhere", FALSE) + keepWhere <- getOption("future.globals.keepWhere", TRUE) if (!keepWhere) { where <- attr(globals, "where") for (kk in seq_along(where)) where[[kk]] <- emptyenv() diff --git a/tests/globals,S4methods.R b/tests/globals,S4methods.R index 7ba96d80..5a8b8846 100644 --- a/tests/globals,S4methods.R +++ b/tests/globals,S4methods.R @@ -1,9 +1,6 @@ source("incl/start.R") library(methods) -## Required for S4 methods to work -options(future.globals.keepWhere = TRUE) - message("*** Globals - S4 methods ...") setGeneric("my_fcn", function(x) standardGeneric("my_fcn")) diff --git a/tests/globals,locals.R b/tests/globals,locals.R index e087d273..91dc35a3 100644 --- a/tests/globals,locals.R +++ b/tests/globals,locals.R @@ -5,8 +5,6 @@ oopts <- c(oopts, options( future.globals.onMissing = "error" )) -okeep <- list() - message("*** Globals inside local() environments ...") for (strategy in supportedStrategies()) { @@ -68,7 +66,7 @@ for (strategy in supportedStrategies()) { truth <- g() + h() print(truth) - ## Fixed in future (>= 1.25.0-9013) with globals (>= 0.14.0.9004): + ## Fixed in future (>= 1.25.0-9016) with globals (>= 0.14.0.9004): ## ## f <- future(g() + h()) ## @@ -79,13 +77,10 @@ for (strategy in supportedStrategies()) { ## ## 'a' of h() would overwride 'a' of g() so that g() == 1 ## https://github.com/HenrikBengtsson/future/issues/608 - if (is.null(getOption("future.globals.keepWhere")) && packageVersion("globals") >= "0.14.0.9004") { - okeep <- options(future.globals.keepWhere = TRUE) - } f <- future(g() + h()) v <- tryCatch(value(f), error = identity) print(v) - if (isTRUE(getOption("future.globals.keepWhere")) || ! strategy %in% c("sequential", "multicore")) { + if (isTRUE(getOption("future.globals.keepWhere", TRUE)) || ! strategy %in% c("sequential", "multicore")) { stopifnot(identical(v, truth)) } else { if (packageVersion("globals") >= "0.14.0.9004") { @@ -94,8 +89,6 @@ for (strategy in supportedStrategies()) { stopifnot(identical(v, 4)) } } - - options(okeep) } ## for (strategy ...) message("*** Globals inside local() environments ... DONE")