Objects used within R6 methods not properly exported to multisession workers

未关闭
#804 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
r

调研方向

首先运行提供的、使用 R6、future.apply、dplyr 和 multisession 的复现,并将其与 sequential 和 multicore 进行比较。跟踪 R6 方法中的 future_lapply 回调如何识别 globals 和包依赖,然后添加覆盖测试,显示 multisession 返回预期的五个结果组成的列表。

由索引模型根据 Issue 内容生成。

描述

bug

Describe the bug

When using R6, future doesn't seem the objects to export within R6 methods.

Reproduce example

library(R6)
library(future)
library(future.apply)
library(dplyr)

test_class <- R6::R6Class(
  public = list(
    df = data.frame(a = 1),
    simulate = function() {
      self$df %>% mutate(result = a * rnorm(nrow(self$df)))
    },
    run_many_times = function(times=10) {
      results <- future_lapply(1:times, function(i) {
        self$simulate()
      }, future.seed = T)
      return(results)
    }
))

instance <- test_class$new()

plan(sequential)
instance$run_many_times(2)

plan(multicore)
instance$run_many_times(5)

plan(multisession)
instance$run_many_times(5)

The sequential and multicore runs work fine, but the multisession fails with:

Error in self$df %>% mutate(result = a * rnorm(nrow(self$df))) : 
  could not find function "%>%"

Expected behavior

Running the instance$run_many_times returns a list of 5 elements, whether using the default backend, multicore, or multisession.

Session information

Please share your session information after the error has occurred so that we also see which packages and versions are involved;

> sessionInfo()

R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.7.6

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

Random number generation:
 RNG:     L'Ecuyer-CMRG 
 Normal:  Inversion 
 Sample:  Rejection 
 
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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_1.1.4         future.apply_1.11.2 future_1.58.0       R6_2.5.1           

loaded via a namespace (and not attached):
 [1] digest_0.6.37     codetools_0.2-20  tidyselect_1.2.1  magrittr_2.0.3    glue_1.7.0       
 [6] tibble_3.3.0      parallel_4.4.0    pkgconfig_2.0.3   generics_0.1.4    lifecycle_1.0.4  
[11] cli_3.6.4         parallelly_1.45.1 vctrs_0.6.5       compiler_4.4.0    globals_0.18.0   
[16] tools_4.4.0       listenv_0.9.1     pillar_1.10.2     rlang_1.1.5       jsonlite_1.9.1   

> future::futureSessionInfo()
*** Package versions
future 1.58.0, parallelly 1.45.1, parallel 4.4.0, globals 0.18.0, listenv 0.9.1

*** Allocations
availableCores():
           system /proc/self/status 
               10                10 
availableWorkers():
$system
 [1] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
 [9] "localhost" "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=FALSE

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

*** Basic tests
Main R session details:
   pid     r sysname release
1 2480 4.4.0  Darwin  23.6.0
                                                                                                       version
1 Darwin Kernel Version 23.6.0: Thu Apr 24 20:29:18 PDT 2025; root:xnu-10063.141.1.705.2~1/RELEASE_ARM64_T6000
  nodename machine   login    user effective_user
1  host001   arm64 user002 user001        user001
Worker R session details:
  worker  pid     r sysname release
1      1 2480 4.4.0  Darwin  23.6.0
                                                                                                       version
1 Darwin Kernel Version 23.6.0: Thu Apr 24 20:29:18 PDT 2025; root:xnu-10063.141.1.705.2~1/RELEASE_ARM64_T6000
  nodename machine   login    user effective_user
1  host001   arm64 user002 user001        user001
Number of unique worker PIDs: 1 (as expected)
主要语言
R
星标
1k
派生
93
平均合并
2 天 4 小时
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

futureverse/future 的其他 Issue

查看 futureverse/future 的全部 Issue

相似的 Issue

更多 R Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。