0

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.

Sergej S
  • 37
  • 4

2 Answers2

1

This is a bug in some relatively new code to speed up the underlying function crosspairs.ppp(). Until a new version of spatstat.geom is available you can workaround the problem by setting spatstat.options("crosspairs.newcode" = FALSE) as suggested.

Ege Rubak
  • 4,347
  • 1
  • 10
  • 18
1

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

Adrian Baddeley
  • 2,534
  • 1
  • 5
  • 8