myfunction
の各行に並行して適用したいとしますmyDataFrame
。otherDataFrame
が 2 つの列を持つデータフレームであるとします:でCOLUNM1_odf
何らかのCOLUMN2_odf
理由で使用されmyfunction
ます。したがって、次のようなコードを使用して記述したいと思いparApply
ます。
clus <- makeCluster(4)
clusterExport(clus, list("myfunction","%>%"))
myfunction <- function(fst, snd) {
#otherFunction and aGlobalDataFrame are defined in the global env
otherFunction(aGlobalDataFrame)
# some code to create otherDataFrame **INTERNALLY** to this function
otherDataFrame %>% filter(COLUMN1_odf==fst & COLUMN2_odf==snd)
return(otherDataFrame)
}
do.call(bind_rows,parApply(clus,myDataFrame,1,function(r) { myfunction(r[1],r[2]) }
ここでの問題は、R が認識しないCOLUMN1_odf
ことCOLUMN2_odf
ですclusterExport
。どうすればこの問題を解決できますか? snow
それぞれを列挙しないために必要なすべてのオブジェクトを「エクスポート」する方法はありますか?
otherDataFrame
編集 1:が内部的に作成されることを指定するために、(上記のコードに) コメントを追加しましたmyfunction
。
編集2:一般化するためにいくつかの擬似コードを追加しましたmyfunction
:グローバルデータフレーム(aGlobalDataFrame
および別の関数otherFunction
)を使用するようになりました