Search code examples
spatstat

spatstat integer overflow error in Kcross and crosspairs


I'm working with spatstat 2.3-4 in R 4.1.0 on a 64bit windows 10 pro machine. Recently I ran into the integer-overflow error while using Kcross with a large number of points (i.e. the number of combination exceeded .Machine$integer.max). For example:

W <- as.owin(list(xrange = c(688.512, 17879.746) , yrange = c(-27996.842, -7759.813))) 
cells1 <- runifpoint(n = 8062, win = W)
cells2 <- runifpoint(n = 1768988, win = W) 
cells3 <- superimpose(tumor = cells1 , bcell = cells2)
Kcross(cells3 , r = seq(0,200,by=5) , "tumor" , "bcell" , correction="none") # error
# Error in if (nXY <= 1024) { : missing value where TRUE/FALSE needed 
# In addition: Warning message: In nX * nY : NAs produced by integer overflow 
8062 * 1768988 > .Machine$integer.max
# [1] TRUE

After a lot of struggling I realized that the error comes from this part of crosspairs:

if (spatstat.options("crosspairs.newcode")) {
      nXY <- nX * nY
      if (nXY <= 1024) {
          nsize <- 1024
      }  

I could "fix" the error by changing spatstat options: spatstat.options("crosspairs.newcode" = FALSE).

Is this the way to deal with the error?

UPDATE: As Adrian.Baddeley answered below, there is now a new spatstat.geom version on GitHub (currently: v2.4.-0.029) in which the bug is fixed. The new version works fine without the change of the options.


Solution

  • The bug is fixed in the development version of spatstat.geom available at the GitHub repository