如何从'parlappy'函数调用全局函数?
如何从如何从'parlappy'函数调用全局函数?,r,parallel-processing,R,Parallel Processing,如何从parlappy函数调用全局函数speedDistribution speedDistribution <- function(speed) { return(quantile(speed, seq(0.2, 1, by = 0.20))) } estimateFeatures <- function(trips,target) { cl <- makeCluster( 4 ) features = NULL features = parLapply(c
parlappy
函数调用全局函数speedDistribution
speedDistribution <- function(speed)
{
return(quantile(speed, seq(0.2, 1, by = 0.20)))
}
estimateFeatures <- function(trips,target)
{
cl <- makeCluster( 4 )
features = NULL
features = parLapply(cl, 1:length(trips), function(z){
z <- as.data.frame(z)
speed <- 3.6 * sqrt(diff(z$x)^2 + diff(z$y)^2)
s <- speed[!speed > mean(speed) + sd(speed) * 5]
features = c(speedDistribution(s),target)
return(cbind(features, rep(z, nrow(features))))
})
stopCluster(cl)
return(features)
}
speedDistribution您需要导出该功能,以便使用clusterExport
功能的所有工作人员都可以使用该功能。加:
clusterExport(cl, "speedDistribution")
在您尝试计算之前。这里仅是猜测,paraply()
正在创建/攻击一些不允许全局范围的本地环境(默认情况下,R在环境中向上搜索)。尝试将speedDistribution()
函数放入parlappy()
的lambda函数中。