<div dir="ltr"><div><span style="color:rgb(32,31,30);font-size:14.6667px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline;float:none"></span></div><div><span style="color:rgb(32,31,30);font-size:14.6667px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline;float:none">Hi, I'm a bit new to coding in C++, but I'm wondering if anyone knows what could cause the R Session to abort when running functions coded in C++. I've tried with R 3.6.3 and R 4.0.3, as well as with the latest CRAN release and the release on drat. I'm working on some sliding window processing functions for raster data, and for some reason on my data it often, but not always, causes my R session to abort if I use a window size of 17 or greater. The function works fine for smaller window sizes, and even works with a window size of 17 for rasters of the same size filled with random numbers. The source code for my functions is available on github at (<a href="https://github.com/ailich/GLCMTextures,">https://github.com/ailich/GLCMTextures,</a>) and I've included an example script below that includes how to install the R package.<br><br>devtools::install_github("ailich/GLCMTextures") #Install my package from github<br></span></div><div><span style="color:rgb(32,31,30);font-size:14.6667px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline;float:none"><br></span></div><div><span style="color:rgb(32,31,30);font-size:14.6667px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline;float:none">library(raster)<br>library(GLCMTextures) #Load libraries<br><br>data("test_mat") #Load test data<br><br>r<- raster(test_mat) #Convert to raster<br>rq<- quantize_raster(r, n_levels = 4, method = "equal prob") #quantize range to 0-3<br>plot(rq)<br>?glcm_textures #pull up help file<br><br>#Runs fine<br>test1<- glcm_textures(r = rq, w = c(15,15), n_levels = 4, quantization = "none", shift=c(-1,1)) #R function<br>test2<- GLCMTextures:::C_glcm_textures_helper(rq = as.matrix(rq), w = c(15,15), n_levels = 4, shift = c(-1,1)) #Internal C++ function called within the R function<br><br>#Usually causes R to abort (But sometimes runs for some reason)</span></div><div><span style="color:rgb(32,31,30);font-size:14.6667px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline;float:none">#If this section runs, usually will not run if you clear the environment, restart R, and try again</span></div><div><span style="color:rgb(32,31,30);font-size:14.6667px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline;float:none">test3<- glcm_textures(r = rq, w = c(17,17), n_levels = 4, quantization = "none", shift=c(-1,1)) #R function<br>test4<- GLCMTextures:::C_glcm_textures_helper(rq = as.matrix(rq), w = c(17,17), n_levels = 4, shift = c(-1,1)) #Internal C++ function called within the R function glcm_textures<br><br>#From playing around with it and commenting out code blocks, C_glcm_textures_helper seems to crash at the call to C_make_glcm</span></div><div><span style="color:rgb(32,31,30);font-size:14.6667px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline;float:none"><br></span></div><div><span style="color:rgb(32,31,30);font-size:14.6667px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline;float:none">#Create a new dataset of same size (This runs)<br>rq2<- rq #Make new data equal to old data<br>values(rq2)<- sample(0:3, size = nrow(rq2)*ncol(rq2), replace = TRUE) #Replace with random values in same range</span></div><div><span style="color:rgb(32,31,30);font-size:14.6667px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;display:inline;float:none">plot(rq2)<br>test4<- glcm_textures(r = rq2, w = c(17,17), n_levels = 4, quantization = "none", shift=c(-1,1)) #Since it runs on a raster of the same size it doesn't seem to be that it's too large for the C++ memory.<br></span></div>

</div>