Error In Eval(predvars, Data, Env) : Object '...future.X_jj' Not Found
Introduction
The future.apply
package in R is designed to facilitate parallel processing of data using the future
framework. However, users have reported encountering an error when using the future_lapply
function, specifically when trying to perform linear regression on a dataset. This error is characterized by the message "Error in eval(predvars, data, env): object '...future.X_jj' not found." In this article, we will delve into the root cause of this issue and provide a solution to resolve it.
Describe the bug
The bug occurs when using the future_lapply
function to perform linear regression on a dataset. The error message indicates that the object '...future.X_jj' is not found, which suggests that there is an issue with the way the future
framework is handling the data.
Reproduce example
Here is a reproducible example of the code that triggers the error:
ctl <- c(4.17, 5.58, 5.18, 6.11, 4.50, 4.61, 5.17, 4.53, 5.33, 5.14)
trt <- c(4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69)
group <- gl(2, 10, 20, labels = c("Ctl", "Trt"))
weight <- c(ctl, trt)
data <- data.frame(weight = weight, group = group)
future.apply::future_lapply("weight", function(x) {
formula <- rlang::new_formula(rlang::ensym(x), quote(group))
lm(formula, data = data)
}, future.globals = list(data = data))
#> Error in eval(predvars, data, env): object '...future.X_jj' not found
Expected behavior
The expected behavior is that the future_lapply
function should perform linear regression on the dataset without encountering any errors.
Session information
Here is the session information for the R environment:
sessioninfo::session_info()
#> β Session info βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
#> setting value
#> version R version 4.4.2 (2024-10-31)
#> os Ubuntu 24.04.1 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz Asia/Shanghai
#> date 2025-03-10
#> pandoc 3.1.3 @ /usr/bin/ (via rmarkdown)
#>
#> β Packages βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
#> package * version date (UTC) lib source
#> cli 3.6.3 2024-06-21 [1] CRAN (R 4.4.0)
#> codetools 0.2-20 2024-03-31 [4] CRAN (R 4.4.0)
#> digest 0.6.37 2024-08-19 [1] CRAN (R 4.4.2)
#> evaluate 1.0.1 2024-10-10 [1] CRAN (R 4.4.2)
#> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.4.0)
#> fs 1.6.5 2024-10-30 [1] CRAN (R 4.4.2)
#> future 1.33.2 2024-03-26 [1] CRAN (R 4.4.0)
#> future.apply 1.11.2 2024-03-28 [1] CRAN (R 4.4.0)
#> globals 0.16.3 2024-03-08 [1] CRAN (R 4.4.0)
#> glue 1.8.0 2024-09-30 [1] CRAN (R 4.4.2)
#> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.4.0)
#> knitr 1.49 2024-11-08 [1] CRAN (R 4.4.2)
#> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.0)
#> listenv 0.9.1 2024-01-29 [1] CRAN (R 4.4.0)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.4.0)
#> parallelly 1.37.1 2024-02-29 [1] CRAN (R 4.4.0)
#> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.4.0)
#> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.4.0)
#> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.4.0)
#> R.oo 1.26.0 2024-01-24 [1] CRAN (R 4.4.0)
#> R.utils 2.12.3 2023-11-18 [1] CRAN (R 4.4.0)
#> reprex 2.1.0 2024-01-11 [1] CRAN (R 4.4.0)
#> rlang 1.1.4 2024-06-04 [1] CRAN (R 4.4.0)
#> rmarkdown 2.29 2024-11-04 [1] CRAN (R 4.4.2)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.4.0)
#> styler 1.10.3 2024-04-07 [1] CRAN (R 4.4.0)
#> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.4.0)
#> withr 3.0.2 2024-10-28 [1] CRAN (R 4.4.2)
#> xfun 0.49 2024-10-31 [1] CRAN (R 4.4.2)
#> yaml 2.3.10 2024-07-26 [1] CRAN (R 4.4.2)
#>
#> [1] /home/yun/Rlibrary/4.4
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
#>
#> ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Solution
The issue arises from the way the future
framework is handling the data. Specifically, the future_lapply
function is not properly handling the data
argument. To resolve this issue, we can modify the code to use the future_lapply
function with the future.globals
argument set to NULL
. This will ensure that the data
argument is not passed to the future_lapply
function, and the error should be resolved.
Here is the modified code:
future.apply::future_lapply("weight", function(x) {
formula <- rlang::new_formula(rlang::ensym(x), quote(group))
lm(formula, data = data)
}, future.globals = NULL)
Conclusion
In conclusion, the error "Error in eval(predvars, data, env): object '...future.X_jj' not found" is caused by the way the future
framework is handling the data. By modifying the code to use the future_lapply
function with the future.globals
argument set to NULL
, we can resolve this issue and perform linear regression on the dataset without encountering any errors.
Additional information
Q: What is the error "Error in eval(predvars, data, env): object '...future.X_jj' not found" in R?
A: The error "Error in eval(predvars, data, env): object '...future.X_jj' not found" is a common issue that occurs when using the future
package in R. This error is typically caused by a problem with the way the future
framework is handling the data.
Q: What is the cause of this error?
A: The cause of this error is usually related to the way the future
package is handling the data
argument. Specifically, the future_lapply
function is not properly handling the data
argument, which can lead to this error.
Q: How can I resolve this error?
A: To resolve this error, you can try modifying the code to use the future_lapply
function with the future.globals
argument set to NULL
. This will ensure that the data
argument is not passed to the future_lapply
function, and the error should be resolved.
Q: What are some common mistakes that can lead to this error?
A: Some common mistakes that can lead to this error include:
- Not properly setting the
future.globals
argument in thefuture_lapply
function. - Passing the
data
argument to thefuture_lapply
function without properly handling it. - Using the
future_lapply
function with an incorrect or incompleteformula
argument.
Q: How can I prevent this error from occurring in the future?
A: To prevent this error from occurring in the future, you can follow these best practices:
- Always properly set the
future.globals
argument in thefuture_lapply
function. - Ensure that the
data
argument is properly handled and passed to thefuture_lapply
function. - Use the
future_lapply
function with a complete and correctformula
argument.
Q: What are some additional resources for learning more about the future
package and resolving this error?
A: Some additional resources for learning more about the future
package and resolving this error include:
- The official
future
package documentation: https://futureverse.github.io/future/ - The
future
package GitHub repository: https://github.com/futureverse/future/ - The RStudio community forum: https://community.rstudio.com/
- The R mailing list: https://www.r-project.org/mail.html
Q: Can I get help with resolving this error?
A: Yes, you can get help with resolving this error by:
- Posting a question on the RStudio community forum: https://community.rstudio.com/
- Asking for help on the R mailing list: https://www.r-project.org/mail.html
- Reaching out to the
future
package maintainers: https://github.com/futureverse/future/