R: caught segfault in Maxent

28 views Asked by At

I am trying to run an example code for the Maxent in the R. Please see here.

Here is the code:

library(dismo)
library(rJava)
library(raster)
library(sf)
occurence <- paste(system.file(package="dismo"), '/ex/bradypus.csv', sep='')
occ <- read.table(occurence, header=TRUE, sep=',')[,-1]

# witholding a 20% sample for testing 
fold <- kfold(occ, k=5)
occtest <- occ[fold == 1, ]
occtrain <- occ[fold != 1, ]

files <- list.files(path=paste(system.file(package="dismo"), '/ex',
                               sep=''),  pattern='grd',  full.names=TRUE )
#predictors of the model, the rasters. 
predictors<-stack(files[1:8])

#run the algorithm.
me<-maxent(predictors, occtrain)

The problem is when I run this code inside R console, I will face the following error:

 *** caught segfault ***
address 0xfffffffffffffff0, cause 'invalid permissions'

Traceback:
 1: rJava::.jcall(mxe, "S", "fit", c("autorun", "-e", afn, "-o",     dirout, "-s", pfn, args))
 2: .local(x, p, ...)
 3: maxent(x, p, ...)
 4: maxent(x, p, ...)
 5: .local(x, p, ...)
 6: maxent(predictors, occtrain)
 7: maxent(predictors, occtrain)

The weird fact is if I run my code in the R Interactive console of the vscode(I have the R Extension for Visual Studio Code), it runs normally and provides the desired output.

I am looking for the error and how can I fix it to run my code in the R console.

Btw: I am using Mac M2 processor.

0

There are 0 answers