You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the future_lapply function in a R package that I am currently developing. I run into a problem where the future_lapply function cannot find some functions or objects that are passed from the user to the package.
A minimal working example is as follows where func and func.square represent two functions in my package:
The function func.main has an argument f that represents a function passed from the user.
The function func.square represents a function that carries out some data processing and computations in my package. It is doing a simple arithmetic here for illustration purpose.
However, an error occurs if the user specifies the function as follows where it contains a scalar a and function b that are defined outside the function f:
library(future)
plan(multisession, workers=2)
a<-1b<-function(x) x^2f<-function(x) b(x) +a
func.main(f)
#> Error in b(x) : could not find function "b"
While I understand that this error vanishes if I define the scalar a and function b in the future.globals option of the future_lapply function, the problem is that my package does not know the scalar a and function b in advance as it is something that the user passes to the functions in my package. I also want to maintain the minimum amount of input required from the user.
May I know what would be a workaround to this problem, or is there any method to make sure that the objects a and b can be found?
Thanks for your help in advance!
The text was updated successfully, but these errors were encountered:
Hi @HenrikBengtsson, hope all is well.
I am using the
future_lapply
function in a R package that I am currently developing. I run into a problem where thefuture_lapply
function cannot find some functions or objects that are passed from the user to the package.A minimal working example is as follows where
func
andfunc.square
represent two functions in my package:func.main
has an argumentf
that represents a function passed from the user.func.square
represents a function that carries out some data processing and computations in my package. It is doing a simple arithmetic here for illustration purpose.There is no issue when the function
f
is defined as follows and passed tofunc.main
:However, an error occurs if the user specifies the function as follows where it contains a scalar
a
and functionb
that are defined outside the functionf
:While I understand that this error vanishes if I define the scalar
a
and functionb
in thefuture.globals
option of thefuture_lapply
function, the problem is that my package does not know the scalara
and functionb
in advance as it is something that the user passes to the functions in my package. I also want to maintain the minimum amount of input required from the user.May I know what would be a workaround to this problem, or is there any method to make sure that the objects
a
andb
can be found?Thanks for your help in advance!
The text was updated successfully, but these errors were encountered: