Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some spelling, added an error for lets.presab., document datasets, add test #16

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 63 additions & 54 deletions R/Data_helps.R
Original file line number Diff line number Diff line change
@@ -1,64 +1,73 @@
#'@name IUCN
#'@aliases IUCN
#'@docType data
#'@title IUCN avaliation for frogs of Phyllomedusa genus
#'@usage data(IUCN)
#'@description Result of the function \code{\link{lets.iucn}}
#'applied to Southern American frog genera Phyllomedusa in 2014.
#' IUCN evaluation for frogs of the genus Phyllomedusa
#'
#' Result of the (deprecated) function \code{\link{lets.iucn}}
#' applied to South American frog genus Phyllomedusa in 2014.
#'
#'@format A data frame with 32 rows and 7 columns:
#'\describe{
#' \item{Species}{Scientific name}
#' \item{Family}{Family}
#' \item{Status}{Red List Status}
#' \item{Criteria}{Criteria for listing as threatened}
#' \item{Population}{Population trend per IUCN}
#' \item{Description_Year}{Year described}
#' \item{Country}{Presence in country}
#'}
#'
#'@source IUCN - \url{https://www.iucnredlist.org/}. 2014.
"IUCN"

NULL

#'@name PAM
#'@aliases PAM
#'@docType data
#'@title PresenceAbsence object for frogs of Phyllomedusa genus
#'@usage data(PAM)
#'@description PresenceAbsence object obtained using the function \code{\link{lets.presab}}
#'in the Geographic distribution of the Southern American frog genus \link{Phyllomedusa}.
#'@source IUCN - \url{https://www.iucnredlist.org/}. 2014.
#' PresenceAbsence object for frogs of the genus Phyllomedusa
#'
#' PresenceAbsence object obtained using the function \code{\link{lets.presab}}
#' for the Geographic distribution of the South American frog genus \link{Phyllomedusa}.
#' @format A PresenceAbsence object
#' @source Generated from IUCN Spatial Data - \url{https://www.iucnredlist.org/}. 2014.
"PAM"

NULL
#' Phyllomedusa
#'
#' Geographic distribution of the South American frog genus Phyllomedusa.
# 'Data modified from the IUCN Red List spatial dataset, downloaded 05/2014).
#'
#' See the IUCN Red List Attribute Information for Species Ranges.
#'
#' @format A simple feature collection for 32 species with 46 features and 4 fields.
#'
#' \describe{
#' \item{binomial}{Scientific name}
#' \item{presence}{IUCN Red List distributional code}
#' \item{origin}{IUCN Red List distributional code}
#' \item{seasonal}{IUCN Red List distributional code}
#' }
#' @source IUCN - \url{https://www.iucnredlist.org/}. 2014.
"Phyllomedusa"

#'@name Phyllomedusa
#'@aliases Phyllomedusa
#'@docType data
#'@title Geographic distribution of Phyllomedusa genus
#'@usage data(Phyllomedusa)
#'@description Geographic distribution of the Southern American frog genera Phyllomedusa.
#'Data was modfied from IUCN (\url{https://www.iucnredlist.org/}, downloaded in 05/2014).
#'There are 32 species and 46 polygons.
#'@source IUCN - \url{https://www.iucnredlist.org/}. 2014.

NULL
#' Mean temperature raster for the world.
#'
#' Mean temperature raster in degrees Celsius (multiplied by 100)
#' for the world in 10 arc min of resolution.
#' @format A PackedStatRaster object.
#' @source Data was modified from WorldClim (\url{https://worldclim.com/}, downloaded 05/2014).
#'
#' Hijmans, R.J., S.E. Cameron, J.L. Parra, P.G. Jones and A. Jarvis, 2005.
#' Very high resolution interpolated climate surfaces for global land areas.
#' International Journal of Climatology 25: 1965-1978.
"temp"

#'@name temp
#'@aliases temp
#'@docType data
#'@title Avarege temperature raster for the world.
#'@usage data(temp)
#'@description Average temperature raster in Celsius degrees(multiplied by 100)
#'for the world in 10 arc min of resolution. Data was modfied from
#'WorldClim (\url{https://worldclim.com/}, downloaded in 05/2014).
#'@source Hijmans, R.J., S.E. Cameron, J.L. Parra, P.G. Jones and A. Jarvis, 2005.
#'Very high resolution interpolated climate surfaces for global land areas.
#'International Journal of Climatology 25: 1965-1978.

NULL



#'@name wrld_simpl
#'@aliases wrld_simpl
#'@docType data
#'@title Simplified world country polygons
#'@usage data(temp)
#'@description Shapefile in sf format. The object was obtained from maptools
#' package and converted to sf.
#'@source Originally
#' “https://mappinghacks.com/data/TM_WORLD_BORDERS_SIMPL-0.2.zip”,
#' Simplified world country polygons
#'
#' World map in sf format. Obtained from maptools
#' and converted to sf.
#'
#' @format A simple feature collection with 246 features and 11 fields.
#' @source Originally
#' \url{https://mappinghacks.com/data/TM_WORLD_BORDERS_SIMPL-0.2.zip},
#' now available from
#' https://github.com/nasa/World-Wind-Java/tree/master/WorldWind/testData/shapefiles

#' \url{https://github.com/nasa/World-Wind-Java/tree/master/WorldWind/testData/shapefiles}.
"wrld_simpl"


NULL
33 changes: 20 additions & 13 deletions R/lets_presab.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
#'@param shapes Object of class \code{SpatVect} or \code{Spatial} (see packages
#' \code{\link{terra}} and \code{\link{sf}} to read these files) containing
#' the distribution of one or more species. Species names should be stored in
#' the object as BINOMIAL/binomial or SCINAME/sciname.
#'@param xmx Maximun longitude used to construct the grid in which the matrix
#' the object as BINOMIAL/binomial or SCINAME/sciname.
#'@param xmx Maximum longitude used to construct the grid in which the matrix
#' will be based (i.e. the [gridded] geographic domain of interest).
#' If NULL, limits will be calculated based on the limits of the shapes object.
#'@param xmn Minimun longitude used to construct the grid in which the matrix
#'@param xmn Minimum longitude used to construct the grid in which the matrix
#' will be based (i.e. the [gridded] geographic domain of interest).
#' If NULL, limits will be calculated based on the limits of the shapes object.
#'@param ymx Maximun latitude used to construct the grid in which the matrix
#'@param ymx Maximum latitude used to construct the grid in which the matrix
#' will be based (i.e. the [gridded] geographic domain of interest).
#' If NULL, limits will be calculated based on the limits of the shapes object.
#'@param ymn Minimun latitude used to construct the grid in which the matrix
#'@param ymn Minimum latitude used to construct the grid in which the matrix
#' will be based (i.e. the [gridded] geographic domain of interest).
#' If NULL, limits will be calculated based on the limits of the shapes object.
#'@param resol Numeric vector of length 1 or 2 to set the grid resolution.
Expand Down Expand Up @@ -59,29 +59,29 @@
#' *But see the optional argument \code{show.matrix}.
#'
#'
#'@details The function creates the presence-absence matrix based on a raster
#'@details This function creates the presence-absence matrix based on a raster
#' object. Depending on the cell size, extension used and number of species it
#' may require a lot of memory, and may take some time to process it. Thus,
#' during the process, if \code{count} argument is set \code{TRUE}, a counting
#' window will open so you can see the progress (i.e. in what polygon/shapefile
#' the function is working). Note that the number of polygons is not the same
#' as the number of species that you have (i.e. a species may have more than
#' window will open to display the progress (i.e. the polygon/shapefile
#' that the function is working on). Note that the number of polygons is not the same
#' as the number of species (i.e. a species may have more than
#' one polygon/shapefiles).
#'
#'@seealso \code{\link{plot.PresenceAbsence}}
#'@seealso \code{\link{lets.presab.birds}}
#'@seealso \code{\link{lets.shFilter}}
#'
#' @examples \dontrun{
#' # Spatial distribution polygons of south american frogs
#' # Spatial distribution polygons of South American frogs
#' # of genus Phyllomedusa.
#' data(Phyllomedusa)
#' PAM <- lets.presab(Phyllomedusa)
#' summary(PAM)
#' # Species richness map
#' plot(PAM, xlab = "Longitude", ylab = "Latitude",
#' main = "Phyllomedusa species richness")
#' # Map of the specific species
#' # Map of individual species
#' plot(PAM, name = "Phyllomedusa nordestina")
#'}
#'
Expand All @@ -108,7 +108,14 @@ lets.presab <- function(shapes,
seasonal = NULL,
count = FALSE) {


# look for species names
if(!any(c("binomial","BINOMIAL","SCINAME","sciname") %in% names(shapes)))
{
stop(paste0("species names missing from shapes ",
"or column name in data does not match required names"))
}


shapes <- .check_shape(shapes)

# Projection set for spatial polygons
Expand Down Expand Up @@ -234,7 +241,7 @@ lets.presab <- function(shapes,



# Axuliar function to avoid code repetition inside the loop <<<<<<<<<
# Helper function to avoid code repetition inside the loop <<<<<<<<<

# Function to extract cell positions in the raster
.extractpos <- function(ras,
Expand Down
29 changes: 29 additions & 0 deletions man/IUCN.Rd

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

12 changes: 8 additions & 4 deletions man/PAM.Rd

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

22 changes: 17 additions & 5 deletions man/Phyllomedusa.Rd

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

13 changes: 0 additions & 13 deletions man/iucn.Rd

This file was deleted.

File renamed without changes.
20 changes: 10 additions & 10 deletions man/lets.presab.Rd

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

8 changes: 4 additions & 4 deletions man/lets.presab.birds.Rd

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

Loading
Loading