I am trying to develop a R package that calls functions in an asynchronous way using future::future
. Here is a dummy example:
library(future)
plan(multisession)
test_fun <- function(str) {
Sys.sleep(5)
cat(str)
}
test_future <- function() {
future({test_fun("test")})
}
Calling the function works fine as expected
> f <- test_future()
> value(f)
# test
Nevertheless, if I put these functions in a package structure and load them (for testing) with devtools::load_all(".")
I get an error upon calling the test_future
function.
> devtools::load_all(".")
# ℹ Loading
> f <- test_future()
> value(f)
Error in test_fun("test") : could not find function "test_fun"
I guess its has something to do with the issue that the namespace environment is not available for the future
process, but I do not understand how to come around this.
In the installed package it works fine, but I don’t understand how to test and develop using my normal workflow : implement ➡ load_all ➡ test