R – Solving Error in Function sp.kde from R spatialEco Library in Windows 10 and Debian Linux

r

When I run following R code in a Windows 7 system, result and plot of kde function of spatialEco library is produced without any issues; as it can be observed in below image.

library(spatialEco)
library(sp)
library(rgdal)
points <- readOGR('points.shp')
mask<- readOGR('mask.shp')
bbox<- bbox(mask)
extent<- c(bbox[1], bbox[3], bbox[2], bbox[4])
raster <- sp.kde(x = points, y = points$newpeligro, newdata=extent, bw=1, n = 5000, scale.factor = 100)
plot(raster)
points(points, pch=20, col="red")
plot(mask, add=TRUE)

enter image description here

However, same code ran in Linux or Windows 10 systems produces for below line:

raster <- sp.kde(x = points, y = points$newpeligro, newdata=extent, bw=1, n = 5000, scale.factor = 100)

following error message:

Error in (function (classes, fdef, mtable) : unable to find an
inherited method for function ‘resample’ for signature ‘"RasterLayer",
"numeric"’

In this answer:

https://stackoverflow.com/questions/36943201/what-does-this-mean-unable-to-find-an-inherited-method-for-function-a-for-sig/53124958#53124958

it is suggested that it can be due as result of namespace conflicts.

So, I tried out:

raster <- spatialEco::sp.kde(x = points, y = points$newpeligro, newdata=extent, bw=1, n = 5000, scale.factor = 100)

but the problem still persists. Can this issue be solved?

Best Answer

Oops, found a bug with the extent not being coerced to the correct object class. Just posted a new version of the function in the development version. You can install it using: remotes::install_github("jeffreyevans/spatialEco")

No clear idea on why it is working on Windows 7, as the package version should be the same and this is, in fact, a bug. Perhaps you have an older version of R running under Windows 7 that is using an older package version before this bug was introduced