klmr / klmr/box

`box::use` searches wrong directory inside parallel foreach execution

Open
#312 0 comments 0 reactions 0 assignees View on GitHub
⚠️ bug
Dominant language
R
Stars
979
Forks
49
PR merge metrics
No merged PRs in 30d

Description

### Error description

MWE:

```bash
$ tree mwe
mwe
├── mod.r
└── mwe.r
```

### `mwe/mod.r`

```r
#' @export
run_sqrt <- function (x) {
sqrt(x)
}
```

### `mwe/mwe.r`

```r
box::use(
parallel,
dp = doParallel,
foreach[foreach, `%dopar%`],
)

cl <- parallel$makeCluster(2L)
dp$registerDoParallel(cl)

foreach(i = 1 : 5) %dopar% {
box::use(./mod[...])
run_sqrt(i)
}
```

Run via:

```bash
Rscript mwe/mwe.r
```

Yields the following error:

> ```
> Error in { :
> task 1 failed - " unable to load module “./mod”; not found in “path/to/PWD”"
> Calls: %dopar% ->
> ```

### R version

```plain text
_
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 4
minor 2.0
year 2022
month 04
day 22
svn rev 82229
language R
version.string R version 4.2.0 (2022-04-22)
nickname Vigorous Calisthenics
```

### ‘box’ version

1.1.2.9000

Contributor guide

Open the contributing guide

Research direction

Run Rscript mwe/mwe.r using the provided mwe/mod.r and mwe/mwe.r example to reproduce the failure. Trace how box::use resolves ./mod during the parallel foreach worker execution. Done means the example loads mod.r in each worker and run_sqrt(i) completes without the directory lookup error.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
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.