Skip to content

Commit

Permalink
Allow pamcrop to keep cells
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoVilela committed Mar 26, 2024
1 parent 836c503 commit 61fd739
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ URL: https://besjournals.onlinelibrary.wiley.com/doi/full/10.1111/2041-210X.1240
https://github.com/macroecology/letsR,
https://brunovilela.github.io/letsR/
BugReports: https://github.com/macroecology/letsR/issues
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Encoding: UTF-8
VignetteBuilder: knitr
13 changes: 9 additions & 4 deletions R/lets_pamcrop.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#' \code{terra::vect}) to crop the PresenceAbsence object.
#' @param remove.sp Logical, if \code{TRUE} the final matrix will not contain
#' species that do not match any cell in the grid.
#'
#'@param remove.cells Logical, if \code{FALSE} the final matrix will not contain
#' cells in the grid with a value of zero (i.e. sites with no species present).
#'
#' @return The result is an object of class PresenceAbsence croped.
#'
Expand Down Expand Up @@ -38,7 +39,8 @@
#' @export


lets.pamcrop <- function(x, shp, remove.sp = TRUE) {
lets.pamcrop <- function(x, shp, remove.sp = TRUE,
remove.cells = FALSE) {

if (!methods::is(x, "PresenceAbsence")) {
stop("x is not a PresenceAbsence object")
Expand All @@ -58,8 +60,11 @@ lets.pamcrop <- function(x, shp, remove.sp = TRUE) {

# Remove cells from the matrix
manter <- terra::extract(x[[2]], x[[1]][, 1:2])
x[[1]] <- x[[1]][!is.na(manter[, 1]), ]

if (remove.cells) {
x[[1]] <- x[[1]][!is.na(manter[, 1]), ]
} else {
x[[1]][is.na(manter[, 1]), ] <- 0
}
# Remove species without presence
if (remove.sp) {
x[[1]] <- .removeSp(x[[1]])
Expand Down
5 changes: 4 additions & 1 deletion man/lets.PAMcrop.Rd

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

10 changes: 10 additions & 0 deletions man/letsR-package.Rd

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

0 comments on commit 61fd739

Please sign in to comment.