Skip to content

Commit

Permalink
🔨 stop if neigh = 16
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio-berti committed Aug 30, 2024
1 parent 3d429c5 commit aee952e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions R/enerscape.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Compute Energy Landscapes
data("sirente")#' Compute Energy Landscapes
#'
#' This is the main function to compute energy landscapes from a digital
#' elevation model and body mass of animals based on the model from Pontzer
Expand All @@ -19,9 +19,11 @@
#' library(terra)
#' library(enerscape)
#'
#' data("volcano")
#' dem <- rast(volcano)
#' en <- enerscape(dem, 10, unit = "kcal", neigh = 16)
#' data("sirente")
#' dem <- rast(sirente)
#' en <- enerscape(dem, 10, unit = "kcal", neigh = 8)
#' plot(en, col = hcl.colors(100, "Inferno"))
#' contour(dem, add = TRUE, nlevels = 5, col = hcl.colors(7, "Terrain"))
#' @export
#' @references
#' Pontzer, H. (2016). A unified theory for the energy cost of legged
Expand All @@ -35,13 +37,16 @@ enerscape <- function(
neigh = 8
) {
if (is.null(dem) | is.null(m)) {
stop("Missing mandatory input - see ?enerscape::enerscape for details.")
stop("Missing mandatory input - see ?enerscape for details.")
}
if (!is(dem, "SpatRaster")) {
stop("Digital elevation model must be a SpatRaster (terra).")
stop("'dem' must be a SpatRaster (terra).")
}
if (!unit %in% c("joule", "kcal")) {
stop("unit must be one of 'joule' or 'kcal'.")
stop("'unit' must be one of 'joule' or 'kcal'.")
}
if (neigh != 4 && neigh != 8) {
stop("'neigh' should be either 4 or 8.")
}
# check units of DEM
work_in_kcal <- ifelse(unit == "kcal", TRUE, FALSE)
Expand Down

0 comments on commit aee952e

Please sign in to comment.