[Rcpp-devel] R Session Sometimes Aborts

Dirk Eddelbuettel edd at debian.org
Mon Dec 13 17:33:16 CET 2021


On 13 December 2021 at 11:14, Alexander Ilich wrote:
| 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 focal operations
| <https://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/how-focal-statistics-works.htm>.
| 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 github repository
| <https://github.com/ailich/GLCMTextures/tree/terra>, and I've added some
| sample code below to illustrate the issue.

As frustrating as it is, sometimes the only fix is a rebuild so that all
components use the same ABI/API and headers. I wish we had better diagnostics
for this.  


| Thanks,
| Alex
| 
| install.packages('raster', repos='https://rspatial.r-universe.dev')
| #install development version of raster
| install.packages('terra', repos='https://rspatial.r-universe.dev') #install
| development version of terra

That risks mixing newer and older builds which, for binaries, can have issues.

I know little about the innards of terra and raster so I may be off here.

Dirk

| remotes::install_github("ailich/GLCMTextures", ref = "terra") #Install
| branch of my package testing terra versions of functions
| 
| library(terra)
| library(raster)
| library(GLCMTextures)
| 
| r1a<- raster::raster(volcano)
| r2a<- glcm_textures(r1a, w=c(3,7), n_levels = 16, quantization = "equal
| prob", shift=c(0,1))
| 
| r1b<- terra::rast(volcano)
| r2b<- glcm_textures2(r1b, w=c(3,7), n_levels = 16, quantization = "equal
| prob", shift=c(0,1)) #Often leads to Rsession Aborted
| 
| all.equal(values(r2a),values(r2b)) #TRUE
| 
| 
| 
| #System Information
| #OS: Windows 10
| R.version
| # platform       x86_64-w64-mingw32
| # arch           x86_64
| # os             mingw32
| # system         x86_64, mingw32
| # status
| # major          4
| # minor          0.4
| # year           2021
| # month          02
| # day            15
| # svn rev        80002
| # language       R
| # version.string R version 4.0.4 (2021-02-15)
| # nickname       Lost Library Book
| 
| packageVersion("terra")
| # ‘1.5.2’
| packageVersion("raster")
| # ‘3.5.10’
| packageVersion("Rcpp")
| # ‘1.0.7’
| packageVersion("RcppArmadillo")
| # ‘0.10.7.3.0’
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-- 
https://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list