HenrikBengtsson / future

:rocket: R package: future: Unified Parallel and Distributed Processing in R for Everyone
https://future.futureverse.org
946 stars 82 forks source link

`future_lapply` ran into `subscript out of bounds` error when function have use `$<-` with magrittr pipe. #718

Open yhm-amber opened 3 months ago

yhm-amber commented 3 months ago

Describe the bug

I got a error Error in e[[4]] : subscript out of bounds when I run this:

future.apply::future_lapply (list (a = list ()), \(x) x %>% `$<-` (abc, ""))

and this will not give me that error:

lapply (list (a = list ()), \(x) x %>% `$<-` (abc, ""))

I tested them both in my rstudio and webr repl.

Reproduce example

> future.apply::future_lapply (list (a = list ()), \(x) `$<-` (x, abc, ""))
$a
$a$abc
[1] ""

> future.apply::future_lapply (list (a = list ()), \(x) x %>% `$<-` (abc, ""))
Error in e[[4]] : subscript out of bounds
> lapply (list (a = list ()), \(x) x %>% `$<-` (abc, ""))
$a
$a$abc
[1] ""

> 

S40325-12314156_io github forkmaintainers iceraven

Expected behavior

This error should not happens here.

Session information

> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: wasm32-unknown-emscripten (32-bit)
Running under: emscripten

Matrix products: default

locale:
[1] en_US.UTF-8 C           en_US.UTF-8 en_US.UTF-8 en_US.UTF-8
[6] C          

time zone: Asia/Shanghai
tzcode source: internal

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

other attached packages:
[1] magrittr_2.0.3

loaded via a namespace (and not attached):
 [1] parallelly_1.37.1   parallel_4.3.3      tools_4.3.3        
 [4] webr_0.3.1          listenv_0.9.1       future.apply_1.11.1
 [7] codetools_0.2-19    digest_0.6.35       globals_0.16.3     
[10] future_1.33.1      
> future::futureSessionInfo()
*** Package versions
future 1.33.1, parallelly 1.37.1, parallel 4.3.3, globals 0.16.3, listenv 0.9.1

*** Allocations
availableCores():
system 
     1 
availableWorkers():
$system
[1] "localhost"

*** Settings
- future.plan=<not set>
- future.fork.multithreading.enable=<not set>
- future.globals.maxSize=<not set>
- future.globals.onReference=<not set>
- future.resolve.recursive=<not set>
- future.rng.onMisuse=<not set>
- future.wait.timeout=<not set>
- future.wait.interval=<not set>
- future.wait.alpha=<not set>
- future.startup.script=<not set>

*** Backends
Number of workers: 1
List of future strategies:
1. sequential:
   - args: function (..., envir = parent.frame())
   - tweaked: FALSE
   - call: NULL

*** Basic tests
Main R session details:
  pid     r    sysname release version nodename machine   login
1  42 4.3.3 Emscripten  3.1.47      #1  host001  wasm32 user002
     user effective_user
1 user001        user001
Worker R session details:
  worker pid     r    sysname release version nodename machine
1      1  42 4.3.3 Emscripten  3.1.47      #1  host001  wasm32
    login    user effective_user
1 user002 user001        user001
Number of unique worker PIDs: 1 (as expected)
> 
yhm-amber commented 3 months ago

Why ... %>% '$<-' (...) with future will make this error ? ...

HenrikBengtsson commented 3 months ago

Thanks for the report. I tracked this down to:

> f <- function(x) { x %>% `$<-`(abc, "") }
> codetools::findGlobals(f)
Error in e[[4]] : subscript out of bounds

which means this is outside of Futureverse. So, I think you've actually found a bug in the codetools package. I report to its maintainer.

yhm-amber commented 3 months ago

Thanks for the report. I tracked this down to:

> f <- function(x) { x %>% `$<-`(abc, "") }
> codetools::findGlobals(f)
Error in e[[4]] : subscript out of bounds

which means this is outside of Futureverse. So, I think you've actually found a bug in the codetools package. I report to its maintainer.

Okay, thanks. 😄

And I found that just '$<-' will error, but '[[<-' won't.

Or

foo = `$<-`

at first then use foo will not error also.

HenrikBengtsson commented 3 months ago

Yes; I've just reported at https://gitlab.com/luke-tierney/codetools/-/issues/16