I want to run a parallel loop using foreach and doSnow on a large data frame. the code uses a function from sp package but R report an error saying can't find the function spDistsN1.
# parallel processing
library(foreach)
library(doSNOW)
library(sp)
cl <- makeCluster(4, type="SOCK") # for 4 cores machine
registerDoSNOW (cl)
# parallelization with vectorization
system.time({
output <- foreach(i = 1:nrow(intrp), .combine=c) %dopar% {
which.min(spDistsN1(lonlat[, 1:2], cbind(intrp[i,"LON"], intrp[i,"LAT"]),longlat = FALSE))
}
})
stopCluster(cl)
Am I doing an error here?
Error in { : task 1 failed - "could not find function "spDistsN1""