HenrikBengtsson / future

:rocket: R package: future: Unified Parallel and Distributed Processing in R for Everyone
https://future.futureverse.org
946 stars 82 forks source link

With Sequential/Multicore futures, `conditions = NULL` still signals conditions #613

Closed DavisVaughan closed 2 years ago

DavisVaughan commented 2 years ago

If I understand correctly, conditions = NULL should completely ignore all conditions. It does seem like they aren't propagated up to the user when you execute the future, but if you tryCatch() it you can see that the warning is still being signaled (with sequential and multicore). Strangely, it seems like conditions = character() does the "right" thing here. I thought the two should be identical in behavior.

This came up while trying to add a test to ensure that conditions = NULL doesn't relay any warnings.

library(future)

plan(sequential)

expr <- quote({
  warning("oh no")
  1
})

# We dont see anything about the warning here
value(future(expr, substitute = FALSE, conditions = NULL))
#> [1] 1

# But it still seems to be signaled:
# "Don't intercept any conditions" according to the docs
x <- tryCatch(
  expr = future(expr, substitute = FALSE, conditions = NULL), 
  warning = function(cnd) stop("caught a warning")
)
#> Error in value[[3L]](cond): caught a warning

# `character()` should be identical to `NULL`, right?
# But this one seems to actually ignore all conditions
x <- tryCatch(
  expr = future(expr, substitute = FALSE, conditions = character()), 
  warning = function(cnd) stop("caught a warning")
)

Created on 2022-04-29 by the reprex package (v2.0.1)

DavisVaughan commented 2 years ago

I should also add that if you run the reprex above with reprex::reprex() then even the first example without the tryCatch() will show the warning anyways.

library(future)

plan(sequential)

expr <- quote({
  warning("oh no")
  1
})

# We dont see anything about the warning here (OH WAIT WE DO WITH reprex()!)
value(future(expr, substitute = FALSE, conditions = NULL))
#> Warning in eval(quote({: oh no
#> [1] 1

Created on 2022-04-29 by the reprex package (v2.0.1)

HenrikBengtsson commented 2 years ago

conditions = character(0) captures all conditions and drops them immediately, because there's no match. This comes with some overhead

conditions = NULL doesn't intercept conditions at all, i.e. it won't capture them and let them bubble up to the top. This comes with minimal overhead. It corresponds to what stdout = NA. These are mostly there for low-level troubleshooting. The help page could be improved on this. (Eventually these special values could become an error)

HenrikBengtsson commented 2 years ago

I've updated help(future) to clarify this, cf. https://future.futureverse.org/reference/future.html

DavisVaughan commented 2 years ago

Okay that makes more sense now, thanks!