<div dir="ltr"><div>Hi, I'm upgrading one of my R packages to rely on the terra package instead of the raster package for the handling of spatial raster data. Previously when relying on the raster package I had to convert the data to a matrix and send it to C++ to loop through the cells manually, but with the new features in the terra package I can supply a C++ function that returns multiple values directly to terra::focalCpp to perform <a href="https://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/how-focal-statistics-works.htm">focal operations</a>. I get the same values using both the old and new versions of the functions, but the new version often causes the R session to abort, especially at larger window sizes. For example, a 3x3 or a 3x5 window seems to always run, but a 3x7 window will often cause the R session to abort. However, when it doesn't, I get the correct values. Functions followed by 2 are the terra versions of the function. By commenting out things and rebuilding I was able to determine the line that causes the crash in the terra version is "NumericMatrix curr_GLCM = C_make_glcm(curr_window, n_levels, shift, na_opt); //Tabulate the GLCM"; however, this line is also included in the raster version of the function so I'm not sure why this would happen. Any help would be greatly appreciated. Here is the <a href="https://github.com/ailich/GLCMTextures/tree/terra">github repository</a>, and I've added some sample code below to illustrate the issue.</div><div><br></div><div>Thanks,</div><div>Alex</div><div><br></div><div>install.packages('raster', repos='<a href="https://rspatial.r-universe.dev">https://rspatial.r-universe.dev</a>') #install development version of raster<br>install.packages('terra', repos='<a href="https://rspatial.r-universe.dev">https://rspatial.r-universe.dev</a>') #install development version of terra<br><br>remotes::install_github("ailich/GLCMTextures", ref = "terra") #Install branch of my package testing terra versions of functions<br><br>library(terra)<br>library(raster)<br>library(GLCMTextures)<br><br>r1a<- raster::raster(volcano)<br>r2a<- glcm_textures(r1a, w=c(3,7), n_levels = 16, quantization = "equal prob", shift=c(0,1))<br><br>r1b<- terra::rast(volcano)<br>r2b<- glcm_textures2(r1b, w=c(3,7), n_levels = 16, quantization = "equal prob", shift=c(0,1)) #Often leads to Rsession Aborted<br><br>all.equal(values(r2a),values(r2b)) #TRUE<br><br><br><br>#System Information<br>#OS: Windows 10<br>R.version<br># platform       x86_64-w64-mingw32<br># arch           x86_64<br># os             mingw32<br># system         x86_64, mingw32<br># status<br># major          4<br># minor          0.4<br># year           2021<br># month          02<br># day            15<br># svn rev        80002<br># language       R<br># version.string R version 4.0.4 (2021-02-15)<br># nickname       Lost Library Book<br><br>packageVersion("terra")<br># ‘1.5.2’<br>packageVersion("raster")<br># ‘3.5.10’<br>packageVersion("Rcpp")<br># ‘1.0.7’<br>packageVersion("RcppArmadillo")<br># ‘0.10.7.3.0’</div></div>