Skip to content

Commit

Permalink
alternative function
Browse files Browse the repository at this point in the history
it calculates alpha taxonomic diversity
  • Loading branch information
flaviomoc committed May 20, 2024
1 parent 63ba3c0 commit 7952536
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(area.calc)
export(load.data)
export(spat.alpha)
export(spat.alpha2)
export(spat.beta)
export(spat.rand)
export(spat.trait)
Expand Down
30 changes: 30 additions & 0 deletions R/alpha2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#' Alternative method to calculate alpha taxonomic diversity
#'
#' @param bin A SpatRaster with presence-absence data (0 or 1) for
#' a set of species.
#' @param cores A positive integer. If cores > 1, a 'parallel'
#' package cluster with that many cores is created and used.
#' @param filename Character. Save results if a name is provided.
#'
#' @return A SpatRaster object with richness.
#' @export
#'
#' @examples
#' \donttest{
#' library(terra)
#' bin1 <- terra::rast(system.file("extdata", "ref.tif",
#' package = "divraster"))
#' spat.alpha2(bin1)
#' }
spat.alpha2 <- function(bin, cores = 1, filename = "") {
res <- terra::app(bin, sum, na.rm = TRUE)
names(res) <- "Richness"

if (filename != "") {
terra::writeRaster(res,
filename = filename,
overwrite = TRUE)
}

return(res)
}
31 changes: 31 additions & 0 deletions man/spat.alpha2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7952536

Please sign in to comment.