diff --git a/R/Data_helps.R b/R/Data_helps.R index c6ec9a4..daa9828 100644 --- a/R/Data_helps.R +++ b/R/Data_helps.R @@ -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 diff --git a/R/lets_presab.R b/R/lets_presab.R index e0dce93..5fcdd31 100644 --- a/R/lets_presab.R +++ b/R/lets_presab.R @@ -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. @@ -59,13 +59,13 @@ #' *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}} @@ -73,7 +73,7 @@ #'@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) @@ -81,7 +81,7 @@ #' # 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") #'} #' @@ -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 @@ -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, diff --git a/man/IUCN.Rd b/man/IUCN.Rd new file mode 100644 index 0000000..e9dafc8 --- /dev/null +++ b/man/IUCN.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Data_helps.R +\docType{data} +\name{IUCN} +\alias{IUCN} +\title{IUCN evaluation for frogs of the genus Phyllomedusa} +\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. +} +\usage{ +IUCN +} +\description{ +Result of the (deprecated) function \code{\link{lets.iucn}} +applied to South American frog genus Phyllomedusa in 2014. +} +\keyword{datasets} diff --git a/man/PAM.Rd b/man/PAM.Rd index e8f1f85..739312b 100644 --- a/man/PAM.Rd +++ b/man/PAM.Rd @@ -3,14 +3,18 @@ \docType{data} \name{PAM} \alias{PAM} -\title{PresenceAbsence object for frogs of Phyllomedusa genus} +\title{PresenceAbsence object for frogs of the genus Phyllomedusa} +\format{ +A PresenceAbsence object +} \source{ -IUCN - \url{https://www.iucnredlist.org/}. 2014. +Generated from IUCN Spatial Data - \url{https://www.iucnredlist.org/}. 2014. } \usage{ -data(PAM) +PAM } \description{ PresenceAbsence object obtained using the function \code{\link{lets.presab}} -in the Geographic distribution of the Southern American frog genus \link{Phyllomedusa}. +for the Geographic distribution of the South American frog genus \link{Phyllomedusa}. } +\keyword{datasets} diff --git a/man/Phyllomedusa.Rd b/man/Phyllomedusa.Rd index e867553..580c1f4 100644 --- a/man/Phyllomedusa.Rd +++ b/man/Phyllomedusa.Rd @@ -3,15 +3,27 @@ \docType{data} \name{Phyllomedusa} \alias{Phyllomedusa} -\title{Geographic distribution of Phyllomedusa genus} +\title{Phyllomedusa} +\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. } \usage{ -data(Phyllomedusa) +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. +Geographic distribution of the South American frog genus Phyllomedusa. +} +\details{ +See the IUCN Red List Attribute Information for Species Ranges. } +\keyword{datasets} diff --git a/man/iucn.Rd b/man/iucn.Rd deleted file mode 100644 index 57c1e9a..0000000 --- a/man/iucn.Rd +++ /dev/null @@ -1,13 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/Data_helps.R -\docType{data} -\name{IUCN} -\alias{IUCN} -\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. -} diff --git a/man/lets.PAMcrop.Rd b/man/lets.pamcrop.Rd similarity index 100% rename from man/lets.PAMcrop.Rd rename to man/lets.pamcrop.Rd diff --git a/man/lets.presab.Rd b/man/lets.presab.Rd index 31ad155..3ee40d1 100644 --- a/man/lets.presab.Rd +++ b/man/lets.presab.Rd @@ -29,19 +29,19 @@ lets.presab( the distribution of one or more species. Species names should be stored in the object as BINOMIAL/binomial or SCINAME/sciname.} -\item{xmn}{Minimun longitude used to construct the grid in which the matrix +\item{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.} -\item{xmx}{Maximun longitude used to construct the grid in which the matrix +\item{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.} -\item{ymn}{Minimun latitude used to construct the grid in which the matrix +\item{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.} -\item{ymx}{Maximun latitude used to construct the grid in which the matrix +\item{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.} @@ -97,18 +97,18 @@ Convert species' ranges (in shapefile format) into a presence-absence matrix based on a user-defined grid system } \details{ -The function creates the presence-absence matrix based on a raster +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). } \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) @@ -116,7 +116,7 @@ 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") } diff --git a/man/lets.presab.birds.Rd b/man/lets.presab.birds.Rd index 1421cbd..d1f2412 100644 --- a/man/lets.presab.birds.Rd +++ b/man/lets.presab.birds.Rd @@ -29,19 +29,19 @@ lets.presab.birds( shapefiles. Shapefiles with more than one species will not work on this function. To use multi-species shapefiles see \code{\link{lets.presab}}.} -\item{xmn}{Minimun longitude used to construct the grid in which the matrix +\item{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.} -\item{xmx}{Maximun longitude used to construct the grid in which the matrix +\item{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.} -\item{ymn}{Minimun latitude used to construct the grid in which the matrix +\item{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.} -\item{ymx}{Maximun latitude used to construct the grid in which the matrix +\item{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.} diff --git a/man/lets.presab.points.Rd b/man/lets.presab.points.Rd index 20b4f74..c35ffec 100644 --- a/man/lets.presab.points.Rd +++ b/man/lets.presab.points.Rd @@ -26,19 +26,19 @@ column is the longitude (or x), and the second latitude (or y).} \item{species}{Character vector with species names, in the same order as the coordinates.} -\item{xmn}{Minimun longitude used to construct the grid in which the matrix +\item{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.} -\item{xmx}{Maximun longitude used to construct the grid in which the matrix +\item{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.} -\item{ymn}{Minimun latitude used to construct the grid in which the matrix +\item{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.} -\item{ymx}{Maximun latitude used to construct the grid in which the matrix +\item{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.} diff --git a/man/temp.Rd b/man/temp.Rd index 0e5ab21..a8c0c10 100644 --- a/man/temp.Rd +++ b/man/temp.Rd @@ -3,17 +3,22 @@ \docType{data} \name{temp} \alias{temp} -\title{Avarege temperature raster for the world.} +\title{Mean temperature raster for the world.} +\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. } \usage{ -data(temp) +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). +Mean temperature raster in degrees Celsius (multiplied by 100) +for the world in 10 arc min of resolution. } +\keyword{datasets} diff --git a/man/wrld_simpl.Rd b/man/wrld_simpl.Rd index 5b1d24f..1b73613 100644 --- a/man/wrld_simpl.Rd +++ b/man/wrld_simpl.Rd @@ -4,16 +4,20 @@ \name{wrld_simpl} \alias{wrld_simpl} \title{Simplified world country polygons} +\format{ +A simple feature collection with 246 features and 11 fields. +} \source{ Originally - “https://mappinghacks.com/data/TM_WORLD_BORDERS_SIMPL-0.2.zip”, + \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}. } \usage{ -data(temp) +wrld_simpl } \description{ -Shapefile in sf format. The object was obtained from maptools - package and converted to sf. +World map in sf format. Obtained from maptools +and converted to sf. } +\keyword{datasets} diff --git a/tests/testthat/test-lets_presab.R b/tests/testthat/test-lets_presab.R index 4fb50d9..e5e6b53 100644 --- a/tests/testthat/test-lets_presab.R +++ b/tests/testthat/test-lets_presab.R @@ -168,3 +168,13 @@ test_that("lets.presab new projection grid", { expect_equal(class(PAM2[[3]]), "character") }) + +test_that("lets.presab stops when species names column is missing", { + + Phyllo2 <- Phyllomedusa + names(Phyllo2)[1] <- "species_name" + expect_error( + lets.presab(Phyllo2) + ) + +})