現在、いくつかの大規模なデータセットを扱っているため、ワークフローを並列化することが唯一の方法です。
最初に 1 回、各スレッドにいくつかのパッケージをロードする必要があります (つまり、for(this.thread in threads) { #load some packages }
.
残念ながら、その方法がわかりません。
magrittr
次のコードは、パイプ演算子を aから使用しようとしている私の問題をさらに示しています%dopar%
。
.
library(parallel)
library(doParallel)
library(foreach)
library(magrittr)
# Generate some random data and function :
# -----------------------------------------
randomData = runif(10^3)
randomFunction = function(x) {x * (2^x) }
randomData[1] %>% randomFunction #Works
# And now ... The parallel part :
# --------------------------------
myCluster = makeCluster(6)
registerDoParallel(myCluster)
# Test that the do par is up and running:
foreach(i = randomData) %dopar% { i }
# Use magrittr pipe operator:
# Error in { : task 1 failed - "could not find function "%>%""
foreach(i = randomData) %dopar% { i %>% randomFunction }
# Load the library at each loop: (ie: length(data) times !)
# Other than unnecessarily loading the library (length(data) - numberOfThreads) times,
# it works nicely
foreach(i = randomData) %dopar% { library(magrittr); i %>% randomFunction }
# Now try without re-loading:
# Tararaa - (ie: Works nicely)
foreach(i = randomData) %dopar% { i %>% randomFunction }
.
何か案は?