Scoping problem when sfApply is used within function (package snowfall - R)

前端 未结 2 1632
误落风尘
误落风尘 2020-12-19 11:57

Let me add another scoping problem in R, this time with the snowfall package. If I define a function in my global environment, and I try to use that one later in an sfApply(

相关标签:
2条回答
  • 2020-12-19 12:47

    Methinks you are now confusing scoping with parallel computing. You are invoking new R sessions---and it is commonly your responsibility to re-create your environment on the nodes.

    An alternative would be to use foreach et al. There has examples in the foreach (or iterator ?) docs that show exactly this. Oh, see, and Josh has by now recommended the same thing.

    0 讨论(0)
  • 2020-12-19 13:02

    I think you want to sfExport(func1), though I'm not sure if you need to do it in your .GlobalEnv or inside of func2. Hope that helps...

    > y <- matrix(1:10,ncol=2)
    
    > sfExport(list=list("func1"))
    
    > func2(y)
         [,1] [,2]
    [1,]    2    7
    [2,]    3    8
    [3,]    4    9
    [4,]    5   10
    [5,]    6   11
    
    0 讨论(0)
提交回复
热议问题