Objects used within R6 methods not properly exported to multisession workers

オープン
#804 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
r

調査の方向性

まず、R6、future.apply、dplyr、multisession を使った提供済みの再現コードを実行し、sequential および multicore と比較します。R6 メソッド内の future_lapply コールバックについて、globals とパッケージ依存関係がどのように特定されるかを追跡し、multisession が期待される 5 件の結果のリストを返すことを示すカバレッジを追加します。

索引モデルが 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時間
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

futureverse/future のほかの issue

futureverse/future の issue をすべて見る

似ている issue

R の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。