0

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""

1 Answers1

0

tried running your code , I'm getting error at intrp , have you specified any value ? Also make sure your sp package is updated as i had no error in spDistsN1

my sp version : 1.4-5

enter image description here

CleanCoder
  • 332
  • 3
  • 14