rspatial / predicts

Methods for spatial prediction
GNU General Public License v3.0
10 stars 5 forks source link

Using predict() S4 method for MaxEnt in other package without adding predicts to Depends #17

Closed jamiemkass closed 4 months ago

jamiemkass commented 11 months ago

Hello, thanks for the great update to dismo. I hope you keep building this out to include updates for other dismo functions we've been using for years.

Preface: I am not an expert on R objects, just an amateur, so I might be doing something wrong.

I am trying to update my package ENMeval to use predicts and I am running into an issue with the predict() S4 method. It seems I need to load the predicts package in order to use it. I also cannot figure out how to load this method in NAMESPACE. My maxent.jar models do predict fine using MaxEnt objects after I load predicts. But I would prefer not to have to add predicts to Depends in the DESCRIPTION file. For example, maxnet objects work fine with the generic predict(), but not MaxEnt objects.

Can you advise on how we are supposed to use predict() for MaxEnt and other predicts model objects in other packages?

Thanks for the help,

Jamie

jamiemkass commented 7 months ago

@rhijmans Wondering if you had an idea for how to use predict when it's called in other packages. Thanks.

rhijmans commented 4 months ago

I think the problem has now been solved (by exporting predicts::predict). I can now do:

f <- list.files(path=paste(system.file(package="dismo"), '/ex', sep=''), pattern='grd', full.names=TRUE )
preds <- terra::rast(f)
preds$biome <- terra::as.factor(preds$biome)
occurence <- system.file("/ex/bradypus.csv", package="predicts")
occ <- read.csv(occurence)[,-1]
me <- predicts::MaxEnt(preds, occ)
r1 <- terra::predict(preds, me)
r2 <- predicts::predict(me, preds)
terra::plot(r1)
terra::plot(r2)
jamiemkass commented 3 months ago

Awesome! Thanks very much for this edit. This will make predictions with predicts much easier to implement. Do you have an approximate date for updating the new pkg version for CRAN?