futureverse / futureverse/future.apply

future.apply breaks for functions in custom environments

Open
#130 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
R
Stars
218
Forks
20
Avg merge
2d 9h
Merged PRs (30d)
1

Description

**Describe the bug**

‘future.apply’ does not work with functions defined in ’box’ modules, see klmr/box#386. However, the actual issue is unrelated to ‘box’, and can be reproduced with the following minimal example code, where the function passed to `future.apply::future_lapply()` (or similar) is defined in a custom environment whose parent is not (transitively) the global environment.

**Reproduce example**

```r
local(
future.apply::future_sapply(1 : 5, \(x) x),
envir = new.env(parent = baseenv())
)
```

Or, similarly:

```r
f = \(x) x
environment(f) = new.env(parent = baseenv())

future.apply::future_sapply(1 : 5, f)
```

Both of the above result in the following error (on R 4.5 — on previous versions the behaviour differs, and leads to an infinite loop):

> ```
> Warning: Caught simpleError. Canceling all iterations ...
> Error in `parent.env<-`(`*tmp*`, value = ) :
> cycles in parent chains are not allowed
> ```

**Expected behavior**

The code should work as if being run in the global environment, i.e. it should result in 1 : 5.

**Session information**

```r
> sessionInfo()
```

```
R version 4.5.2 (2025-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Monterey 12.7.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.frame
work/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;
LAPACK version 3.12.1

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

time zone: Europe/Zurich
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] future_1.69.0 nvimcom_0.9.67

loaded via a namespace (and not attached):
[1] compiler_4.5.2 parallelly_1.46.1 parallel_4.5.2 tools_4.5.2
[5] listenv_0.10.0 future.apply_1.20.1 codetools_0.2-20 digest_0.6.39
[9] globals_0.19.0
```

Contributor guide

Open the contributing guide

Research direction

Start by running the two minimal reproductions through future.apply::future_sapply() and inspect how functions and their environments are handled. Done means both examples return 1:5 without a parent-environment cycle error or an infinite loop.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
distributed-systems, hpc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.