[英]Is rouge syntax highlighting meant to highlight non-base functions in R?
[英]Calling functions from non-base R packages in `parallel` package without librarying them within the function
可以说我正在尝试运行以下代码
library(gregmisc)
library(parallel)
myfunction <- function(x){
combinations(10, x, 1:10)
}
cl <- makeCluster(getOption("cl.cores", 2))
parLapply(cl, 3, myfunction)
我收到了错误
#Error in checkForRemoteErrors(val) :
#one node produced an error: could not find function "combinations"
所以,如果我在库中使用“gregmisc”包,它将起作用
myfunction <- function(x){
library(gregmisc)
combinations(10, x, 1:10)
}
cl <- makeCluster(getOption("cl.cores", 2))
parLapply(cl, 3, myfunction)
问题是,如何避免在函数中编写包?
但我无法让它为“并行”包工作
我试过了(没有成功)
library(snow)
library(snowfall)
sfExport(list=list("combinations"))
sfLibrary(gregmisc)
clusterEvalQ(cl, library(gregmisc))
我没有在gregmisc中看到任何combinations
功能。 这可能是你的实际问题吗?
使用clusterEvalQ()
在每个节点上加载包应该有效,并且始终对我有效。 以下代码几乎逐字逐句地从小vignette("parallel")
第8页vignette("parallel")
解除:
require(parallel)
cl <- makeCluster(4)
junk <- clusterEvalQ(cl, library(boot)) ## Discard result
各个节点中的环境不同。 尝试明确指定包:
myfunction <- function(x){
gregmisc::combinations(10, x, 1:10)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.