futureverse / futureverse/future
Cannot forward missing values in futures
- Dominant language
- R
- Stars
- 1k
- Forks
- 92
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
It is a common programming pattern in R to allow function arguments to be missing, and furthermore it is common to "pass on" those missing arguments to another function which will ultimately handle the missing-ness. However, this does not seem to be possible inside a future, as shown by the last line of the reproducible example below.
**Reproduce example**
``` r
library(future)
myfun1 <- function(x, y) {
myfun2(x = x, y = y)
}
myfun2 <- function(x, y) {
if (missing(y)) {
x
} else {
x + y
}
}
future_myfun1 <- function(x, y) {
future(myfun2(x = x, y = y))
}
myfun1(1,2)
#> [1] 3
myfun1(1)
#> [1] 1
value(future_myfun1(1,2))
#> [1] 3
value(future_myfun1(1))
#> Error in get(name, envir = env, inherits = FALSE): Identified global objects via static code inspection (myfun2(x = x, y = y)). argument "y" is missing, with no default
```
Created on 2024-12-17 with [reprex v2.1.1](https://reprex.tidyverse.org)
**Expected behavior**
Ideally `value(future_myfun1(1))` should return the same as `myfun1(1)` instead of throwing an error.
**Session information**
Please share your session information *after* the error has occurred so that we also see which packages and versions are involved;
```r
> sessionInfo()
R version 4.4.2 (2024-10-31)
Platform: aarch64-apple-darwin24.1.0
Running under: macOS Sequoia 15.1.1
Matrix products: default
BLAS: /opt/homebrew/Cellar/openblas/0.3.28/lib/libopenblasp-r0.3.28.dylib
LAPACK: /opt/homebrew/Cellar/r/4.4.2_2/lib/R/lib/libRlapack.dylib; LAPACK version 3.12.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/New_York
tzcode source: internal
attached base packages:
[1] graphics grDevices utils datasets stats methods base
other attached packages:
[1] digest_0.6.37 future.apply_1.11.3-9000 assertthat_0.2.1
[4] tidyr_1.3.1 future_1.34.0 devtools_2.4.5
[7] usethis_3.1.0 openxlsx_4.2.7.1 magrittr_2.0.3
[10] dplyr_1.1.4 rex_1.2.1 glue_1.8.0
[13] stringr_1.5.1 ggplot2_3.5.1 colorout_1.3-2
loaded via a namespace (and not attached):
[1] pROC_1.18.5 remotes_2.5.0 rlang_1.1.4
[4] matrixStats_1.4.1 compiler_4.4.2 callr_3.7.6
[7] vctrs_0.6.5 reshape2_1.4.4 RcppZiggurat_0.1.6
[10] profvis_0.4.0 pkgconfig_2.0.3 shape_1.4.6.1
[13] crayon_1.5.3 fastmap_1.2.0 ellipsis_0.3.2
[16] utf8_1.2.4 promises_1.3.2 rmarkdown_2.29
[19] prodlim_2024.06.25 sessioninfo_1.2.2 ps_1.8.1
[22] purrr_1.0.2 xfun_0.49 Rfast_2.1.0
[25] glmnet_4.1-8 reprex_2.1.1 cachem_1.1.0
[28] recipes_1.1.0 later_1.4.1 matrixTests_0.2.3
[31] parallel_4.4.2 R6_2.5.1 stringi_1.8.4
[34] parallelly_1.40.1 pkgload_1.4.0 rpart_4.1.23
[37] lubridate_1.9.4 knitr_1.49 Rcpp_1.0.13-1
[40] iterators_1.0.14 httpuv_1.6.15 Matrix_1.7-1
[43] splines_4.4.2 nnet_7.3-19 timechange_0.3.0
[46] tidyselect_1.2.1 yaml_2.3.10 rstudioapi_0.17.1
[49] timeDate_4041.110 codetools_0.2-20 miniUI_0.1.1.1
[52] processx_3.8.4 listenv_0.9.1 pkgbuild_1.4.5
[55] lattice_0.22-6 tibble_3.2.1 plyr_1.8.9
[58] shiny_1.9.1 withr_3.0.2 evaluate_1.0.1
[61] survival_3.7-0 nestedcv_0.7.12 RcppParallel_5.1.9
[64] urlchecker_1.0.1 zip_2.3.1 pillar_1.10.0
[67] foreach_1.5.2 stats4_4.4.2 generics_0.1.3
[70] S4Vectors_0.44.0 munsell_0.5.1 scales_1.3.0
[73] globals_0.16.3 xtable_1.8-4 class_7.3-22
[76] clipr_0.8.0 tools_4.4.2 data.table_1.16.4
[79] ModelMetrics_1.2.2.2 gower_1.0.2 fs_1.6.5
[82] grid_4.4.2 ipred_0.9-15 colorspace_2.1-1
[85] nlme_3.1-166 cli_3.6.3 fansi_1.0.6
[88] lava_1.8.0 gtable_0.3.6 BiocGenerics_0.52.0
[91] caret_7.0-1 htmlwidgets_1.6.4 memoise_2.0.1
[94] htmltools_0.5.8.1 lifecycle_1.0.4 hardhat_1.4.0
[97] mime_0.12 MASS_7.3-61
> future::futureSessionInfo()
*** Package versions
future 1.34.0, parallelly 1.40.1, parallel 4.4.2, globals 0.16.3, listenv 0.9.1
*** Allocations
availableCores():
system
12
availableWorkers():
$system
[1] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
[7] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
*** Settings
- future.plan=
- future.fork.multithreading.enable=
- future.globals.maxSize=
- future.globals.onReference=
- future.resolve.recursive=
- future.rng.onMisuse=
- future.wait.timeout=
- future.wait.interval=
- future.wait.alpha=
- future.startup.script=
*** Backends
Number of workers: 1
List of future strategies:
1. sequential:
- args: function (..., envir = parent.frame(), workers = "")
- tweaked: FALSE
- call: plan(sequential)
*** Basic tests
Main R session details:
pid r sysname release
1 94834 4.4.2 Darwin 24.1.0
version
1 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:11 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6020
nodename machine login user effective_user
1 host001 arm64 user001 user002 user002
Worker R session details:
worker pid r sysname release
1 1 94834 4.4.2 Darwin 24.1.0
version
1 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:11 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6020
nodename machine login user effective_user
1 host001 arm64 user001 user002 user002
Number of unique worker PIDs: 1 (as expected)
```
Contributor guide
Assessment
This issue has not been assessed yet.