[Rcpp-devel] R Session Sometimes Aborts
Alexander Ilich
ailich at mail.usf.edu
Mon Dec 13 17:14:34 CET 2021
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.
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
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’
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20211213/c91f39ad/attachment.html>
More information about the Rcpp-devel
mailing list