Skip to content

Commit

Permalink
Fixing moses analyses to work with spatvector
Browse files Browse the repository at this point in the history
Our do.call rbind magic stopped working, turns out with terra all you need to do is call vect() on a list and it does the trick quite handily!
  • Loading branch information
danlwarren committed Jan 16, 2024
1 parent cd8944b commit 74b2078
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ENMTools
Type: Package
Title: Analysis of Niche Evolution using Niche and Distribution Models
Version: 1.1.1
Version: 1.1.2
Date: 2024-01-10
Encoding: UTF-8
Authors@R: c(person(given = "Dan", family = "Warren", role = c("aut", "cre"), email = "dan.l.warren@gmail.com", comment = c(ORCID = "0000-0002-8747-2451")),
Expand Down
2 changes: 1 addition & 1 deletion R/check.species.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ check.species <- function(this.species, env = NA, trim.dupes = FALSE){
}


format.latlon <- function(latlon){
reformat.latlon <- function(latlon){

# Basically this bit just tries to auto-identify the lat and lon columns, then returns a
# reformatted data frame with col names "x" and "y"
Expand Down
4 changes: 2 additions & 2 deletions R/moses.list.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ moses.list <- function(species.list, env, f = NULL, eval = FALSE, nback = 1000,
names(separate.glms) <- lapply(species.list, function(x) x$species.name)
separate.aic <- sum(unlist(lapply(separate.glms, function(x) x$model$aic)))

combined.species <- enmtools.species(presence.points = as.data.frame(do.call("rbind", lapply(species.list, function(x) rbind(x$presence.points)))),
background.points = as.data.frame(do.call("rbind", lapply(species.list, function(x) rbind(x$background.points)))),
combined.species <- enmtools.species(presence.points = terra::vect(lapply(species.list, function(x) rbind(x$presence.points))),
background.points = terra::vect(lapply(species.list, function(x) rbind(x$background.points))),
species.name = "combined")
combined.glm <- enmtools.glm(combined.species, env, f, eval, verbose = verbose, step = step, ...)
combined.aic <- combined.glm$model$aic
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ check.points <- function(pts, name = "input") {
warning(sprintf('%s are not the expected SpatVector class (instead, it is of class %s). ENMTools will attempt to coerce using terra::vect(as.matrix(...), crs = "EPSG:4326"), but we cannot guaranteed the correctness of the result. Please consider using SpatVector format directly in the future, to minimize unexpected results.',
name,
cls))
pts <- format.latlon(pts)
pts <- reformat.latlon(pts)
pts <- terra::vect(as.matrix(pts), crs = "EPSG:4326")
}
pts
Expand Down

0 comments on commit 74b2078

Please sign in to comment.