Using parLapply and clusterExport inside a function

前端 未结 2 1300
刺人心
刺人心 2020-12-07 19:01

I asked a related question here and the response worked well: using parallel's parLapply: unable to access variables within parallel code

The problem is when I

2条回答
  •  情话喂你
    2020-12-07 19:35

    By default clusterExport looks in the .GlobalEnv for objects to export that are named in varlist. If your objects are not in the .GlobalEnv, you must tell clusterExport in which environment it can find those objects.

    You can change your clusterExport to the following (which I didn't test, but you said works in the comments)

    clusterExport(cl=cl, varlist=c("text.var", "ntv", "gc.rate", "pos"), envir=environment())
    

    This way, it will look in the function's environment for the objects to export.

提交回复
热议问题