I'm doing geostatistical interpolations in R on a 5600 x 5700 matrix and, despite having available memory, I'm getting the error "C stack usage is too close to the limit."
There are a few SO questions related to this issue including this one and this one . These sources and others I've seen online suggest changing the stack size often resolves this issue. Some suggested this change: R_CStackLimit = (uintptr_t)-1
in the file "Rinterface.h". However I am on Windows 7 (x64), using R 2.15.3 (x64) via the Rpy2
module (v 2.3.6 x64 by way of Christoph Gohlke ) in Python 2.7, and "Rinterface.h" isn't to be found. How can I otherwise change my effective stack limit for R?
The code that I am running for the interpolation is as follows (except I have it wrapped in a function):
d <- read.table(wd,header=TRUE,sep=',')
d <- na.omit(d)
coordinates(d) <- ~ longdd+latdd ## convert simple data frame into a spatial data frame object
proj4string(d) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
stations <- spTransform(d, CRS(utm19))
names(stations@data)[1] <- "stations"
grids <- readGDAL("dem.asc")
names(grids) <- "dem"
grids$dsea <- readGDAL("dsea.asc")$band1
proj4string(grids) <- CRS(utm19)
ov <- overlay(grids, stations)
stations$dem = ov$dem
stations$dsea = ov$dsea
stations <- stations[!is.na(stations$dsea),]
vgm <- vgm(model="Sph",range=25000)
v <- variogram(air_temp_max_c~dem+dsea,stations)
vgm_max_r<-fit.variogram(v, model=vgm)
temp_uk <- krige(air_temp_max_c~dem+dsea, locations=stations, newdata=grids, model=vgm_max_r)
write.asciigrid(temp_uk[1],outmax)
max_cv <- krige.cv(air_temp_max_c~dem+dsea, locations=stations, vgm_max_r)
max_cv <-data.frame(max_cv)
max_cv["date"] <- dt
max_cv["gs"] <- gs
max_cv["parameter"] <- "air_temp_max_c"
write.table(max_cv,file=<outFile>,sep=",",row.names=F)
you can use #include "Rinterface.h" and put file Rinterface.h in the same file as your C or R code.
The "Rinterface.h" is available at: https://svn.r-project.org/R/trunk/src/include/Rinterface.h
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.