Closed tdhock closed 3 years ago
Thanks, I can reproduce. This somewhat seems familiar to me ... from many years back. I tried to reproduce this using plain futures without future.apply;
library(future)
compute <- function(a, x_vec) {
a + x_vec
}
compute_some_buggy <- function(..., xvec = 1:2) {
compute_one_buggy <- function(x) {
compute(..., x_vec = x)
}
value(future(compute_one_buggy(xvec[1])))
}
plan(cluster, workers = 1L)
x <- compute_some_buggy(2)
print(x)
but this works just fine, which makes me think it's a problem with how the future.apply package handles ...
. I'll investigate.
Oh, forgot to say, the "clean" approach to solve this, is to not rely on global objects (as the inner ...
arguments are in your example), and instead pass them along as arguments. The following works:
compute_some_buggy <- function(..., x_vec = 1:2) {
compute_one_buggy <- function(x, ...) {
compute(..., x_vec = x)
}
future.apply::future_sapply(x_vec, FUN = compute_one_buggy, ...)
}
BTW, I think we tend to be more forgiving about leaving ...
implicit than named arguments - it's not uncommon to see your approach. However, it's always safer to make sure every function doesn't operate on globals - even if they function is a local function.
Hi thanks for the feedback and suggestion about passing the dots through / avoiding references to globals.
This has been fixed in the develop branch, where I also added a package test based on your example, cf. commit ebda4df.
great thanks
... and future.apply 1.8.1 is on CRAN now
hi @HenrikBengtsson hope all is well. Just noticed an inconsistency between the results of multicore and multisession when using future_lapply on a function that refers to dots
...
in its code/body. I expected that multicore and multisession should always give the same results (result should be independent of plan) and I did not see this in the documentation nor in the issues, so I'm filing a new one. Here is a MREThe output that I get on my system is
I expected the second call to compute_some_buggy to return the same thing as the first. (1 2)
This seems to be a problem with finding the right place to evaluate the dots, because actually this works: