[Rcpp-devel] R Session Aborted when calling C++

Alexander Ilich ailich at mail.usf.edu
Thu Oct 29 19:39:16 CET 2020


Thank you Greg. That change worked perfectly! Not sure why that wasn't
always causing problems, but that fixed the issue and I pushed the changes
to github. Also, thank you Dirk for the additional resources.

On Wed, Oct 28, 2020 at 7:43 PM Alexander Ilich <ailich at mail.usf.edu> wrote:

> Oh, sorry. A comma got tacked onto the end of that link accidentally. Just
> remove that trailing comma or use this (
> https://github.com/ailich/GLCMTextures)
>
> On Wed, Oct 28, 2020 at 7:28 PM Alexander Ilich <ailich at mail.usf.edu>
> wrote:
>
>> 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 (https://github.com/ailich/GLCMTextures,) and I've included an
>> example script below that includes how to install the R package.
>>
>> devtools::install_github("ailich/GLCMTextures") #Install my package from
>> github
>>
>> library(raster)
>> library(GLCMTextures) #Load libraries
>>
>> data("test_mat") #Load test data
>>
>> r<- raster(test_mat) #Convert to raster
>> rq<- quantize_raster(r, n_levels = 4, method = "equal prob") #quantize
>> range to 0-3
>> plot(rq)
>> ?glcm_textures #pull up help file
>>
>> #Runs fine
>> test1<- glcm_textures(r = rq, w = c(15,15), n_levels = 4, quantization =
>> "none", shift=c(-1,1)) #R function
>> 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
>>
>> #Usually causes R to abort (But sometimes runs for some reason)
>> #If this section runs, usually will not run if you clear the environment,
>> restart R, and try again
>> test3<- glcm_textures(r = rq, w = c(17,17), n_levels = 4, quantization =
>> "none", shift=c(-1,1)) #R function
>> 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
>>
>> #From playing around with it and commenting out code blocks,
>> C_glcm_textures_helper seems to crash at the call to C_make_glcm
>>
>> #Create a new dataset of same size (This runs)
>> rq2<- rq #Make new data equal to old data
>> values(rq2)<- sample(0:3, size = nrow(rq2)*ncol(rq2), replace = TRUE)
>> #Replace with random values in same range
>> plot(rq2)
>> 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.
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20201029/87103363/attachment.html>


More information about the Rcpp-devel mailing list