Closed ismirsehregal closed 2 years ago
Thanks for the report and sorry to hear that your tool broke all of a sudden.
So, the update in future 1.25.0 to undo any changes to R options and environment variables done by a future expression is very much intentional. It was done to minimize the risk for a future expression to have side effects that affect R elsewhere - I'm basically pushing for futures to be evaluated as if they were evaluated in a sandboxed environment. Now, despite running tons of checks that this did not break anything, I missed this behavior of data.table.
A minimal reproducible example without shiny is:
library(data.table)
#> data.table 1.14.2 using 4 threads (see ?getDTthreads). Latest news: r-datatable.com
library(future)
plan(multisession, workers = 2)
f <- future(data.table())
v <- value(f)
print(v)
#> Null data.table (0 rows and 0 cols)
f <- future(data.table())
v <- value(f)
#> Error in setalloccol(ans) : verbose must be TRUE or FALSE
This is a serious regression that needs to be fixed asap. This might be a design bug in data.table, it might be a bug in future, or I might have to reconsider the undoing of R options in future - I'll investigate.
A workaround, until this has been resolved, is to run the following immediately after setting the future plan;
## May 'datatable.*' R options created by the data.table package stick
dummy <- value(lapply(seq_len(nbrOfWorkers()), FUN = function(ii) {
future(NULL, packages = "data.table", earlySignal = TRUE)
}))
FWIW, I've reported the underlying problem to https://github.com/Rdatatable/data.table/issues/5375, because I argue data.table should handle this. Having said that, I also think I can avoid this in future, so I'll fix/workaround it there too. This problem is unique to cluster/multisession futures.
I've fixed this in future (>= 1.25.0-9005). Please install the develop version and retry. See https://future.futureverse.org/#pre-release-version for how to install it.
PS. There are corner cases where it still can break, e.g. when someone calls future(library(data.table))
before actually using any data.table functions.
@HenrikBengtsson thank you for your swift investigation! I can confirm that the issue is gone after installing the dev version of library(future)
. From my side this issue can be closed - Cheers!
Thanks for confirming.
FYI, future 1.26.1 fixing this problem just hit CRAN.
FYI, future 1.26.1 fixing this problem just hit CRAN.
Just bumped into this issue today with version 1.25.0, and glad that there's a fix in place.
Appreciate your work @HenrikBengtsson 🙏
Describe the bug
After updating
library(future)
to the latest CRAN version (1.25.0) one of my shiny apps (was running fine for a few years already) which is making use of futures is broken.It seems that global options become unset on the second run of the future (but
library(data.table)
requires them to be set). I can work around this issue by setting the required options inside the future (see the comment in the below example code), however, the same happens with global variables (or variables generated in theparent.frame
respectively) as described here leading to "argument is of length zero" errors in several places.The NEWS mentions:
I'm wondering how I can get back the old behaviour. Do I have to set all options and globals manually for each future?
Reproduce example
Expected behavior
Keeping options and globals after a future is resolved
Session information