The documentation for spdep::poly2nb
contains the following entry under Arguments:
foundInBox
: default NULL using R code, possibly parallelised if a snow cluster is available, otherwise a list of length (n-1) with integer vectors of candidate neighbours (j > i), or NULL if all candidates were (j < i) (as created by the poly_findInBoxGEOS function in rgeos for clean polygons)
I have interpreted the part in bold as the function will be parallelized if this argument is NULL (default) and a snow cluster is registered. I have tried doing it like this:
cl <- parallel::makeCluster(7)
doParallel::registerDoParallel(cl)
spdep::poly2nb(squamate_dist) # squamate_dist is a large SpatialPolygonDataFrame
Looking at Task Manager doesn't show any parallelization. What is the correct way to run this function in parallel? Also, is there a way to parallelize it while supplying a list to argument foundInBox
?
The
spdep
package (1.1-8) uses functions likespdep::set.mcOption
to set up parallel computations. See the example in?spdep::set.mcOption
on how they do it.I can't confirm that this works for
spdep::poly2nb
but it worked for me when usingspdep::skater
orspdep::nbcosts
.In a function I use it like this: