diff --git a/DESCRIPTION b/DESCRIPTION index 0d927864..ea48ba86 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: wallace -Version: 2.0.6 -Date: 2023-09-05 +Version: 2.1.0 +Date: 2023-09-25 Title: A Modular Platform for Reproducible Modeling of Species Niches and Distributions Description: The 'shiny' application Wallace is a modular platform for @@ -45,7 +45,6 @@ Imports: magrittr, methods, RColorBrewer, - rgeos, rJava, rlang, rmarkdown, diff --git a/NEWS.md b/NEWS.md index 4a1ebdbb..316d2669 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +wallace 2.1.0 +============= +- Removed `rgeos` (package expiring) +- Updated team bios +- Added clarification to occs_queryDb guidance text +- Added error msgs to xfer_time + wallace 2.0.6 ============= - Removed `paleobioDB` (package off CRAN) diff --git a/R/penvs_bgExtent.R b/R/penvs_bgExtent.R index 2d4e23ac..79b31ad9 100644 --- a/R/penvs_bgExtent.R +++ b/R/penvs_bgExtent.R @@ -26,7 +26,7 @@ #' occs$occID <- 1:nrow(occs) #' bgExt <- penvs_bgExtent(occs, bgSel = 'bounding box', bgBuf = 0.5) #' -#' @return A SpatialPolygonsDataFrame object that contains all occurrences from occs +#' @return A SpatialPolygons object that contains all occurrences from occs #' @author Jamie Kass #' @author Gonzalo E. Pinilla-Buitrago # @note @@ -51,6 +51,10 @@ penvs_bgExtent <- function(occs, bgSel, bgBuf, logger = NULL, spN = NULL) { # make spatial pts object of original occs and preserve origID occs.sp <- sp::SpatialPointsDataFrame(occs.xy, data = occs['occID']) + # make an sf obj + occs.sf <- sf::st_as_sf(occs.xy, coords = c("longitude", "latitude")) + occs.sf <- sf::st_union(occs.sf, by_feature = FALSE) + # generate background extent - one grid cell is added to perimeter of each shape # to ensure cells of points on border are included if (bgSel == 'bounding box') { @@ -70,22 +74,29 @@ penvs_bgExtent <- function(occs, bgSel, bgBuf, logger = NULL, spN = NULL) { bgExt <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(as.matrix(xy.bord))), 1))) msg <- "Study extent: minimum convex polygon." } else if (bgSel == 'point buffers') { - if (bgBuf == 0) { + if (bgBuf <= 0) { logger %>% writeLog(type = 'error', - 'Change buffer distance to positive or negative value.') + 'Change buffer distance to a positive value.') return() } - bgExt <- rgeos::gBuffer(occs.sp, width = bgBuf) + bgExt <- sf::st_buffer(occs.sf, dist = bgBuf) msg <- paste0("Study extent: buffered points. Buffered by ", bgBuf, " degrees.") } - if (bgBuf > 0 & bgSel != 'point buffers') { - bgExt <- rgeos::gBuffer(bgExt, width = bgBuf) + if (bgBuf >= 0 & bgSel != 'point buffers') { + bgExt <- sf::st_as_sf(bgExt) + bgExt <- sf::st_buffer(bgExt, dist = bgBuf) logger %>% writeLog(hlSpp(spN), msg, ' Buffered by ', bgBuf, ' degrees.') + } else if (bgBuf < 0 & bgSel != 'point buffers') { + logger %>% + writeLog(type = 'error', + 'All localities must be included within extent. + Change buffer distance to a positive value.') + return() } else { logger %>% writeLog(hlSpp(spN), msg) } - bgExt <- methods::as(bgExt, "SpatialPolygonsDataFrame") + bgExt <- sf::as_Spatial(bgExt) return(bgExt) } diff --git a/R/penvs_drawBgExtent.R b/R/penvs_drawBgExtent.R index ebd89b34..75c3935e 100644 --- a/R/penvs_drawBgExtent.R +++ b/R/penvs_drawBgExtent.R @@ -35,9 +35,9 @@ #' ncol = 2) #' drawBgBf <- penvs_drawBgExtent(polyExtXY = expertDrawPoly, polyExtID = 1, #' drawBgBuf = 0.5, occs) -#' @return This functions returns a SpatialPolygonsDataFrame based on the user -#' specified coordinates (drawn on map). This SpatialPolygonsDataFrame may be -#' larger than specified if drawBgBuf > 0. The SpatialPolygonsDataFrame will +#' @return This functions returns a SpatialPolygons object based on the user +#' specified coordinates (drawn on map). This SpatialPolygons object may be +#' larger than specified if drawBgBuf > 0. The SpatialPolygons object will #' include all occurrences. #' @author Jamie Kass @@ -56,10 +56,12 @@ penvs_drawBgExtent <- function(polyExtXY, polyExtID, drawBgBuf, occs, newPoly <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(polyExtXY)), ID = polyExtID))) intersect <- sp::over(pts, newPoly) + newPoly.sf <- sf::st_as_sf(newPoly) + ptRem <- ifelse(all(!is.na(intersect)), 0, as.numeric(which(is.na(intersect)))) if (ptRem == 0) { - bgExt <- rgeos::gBuffer(newPoly, width = drawBgBuf) - bgExt <- methods::as(bgExt, "SpatialPolygonsDataFrame") + bgExt <- sf::st_buffer(newPoly.sf, dist = drawBgBuf) + bgExt <- sf::as_Spatial(bgExt) if (drawBgBuf == 0) { logger %>% writeLog(hlSpp(spN), 'Draw polygon without buffer.') } else { diff --git a/R/penvs_userBgExtent.R b/R/penvs_userBgExtent.R index f73760d8..32184233 100644 --- a/R/penvs_userBgExtent.R +++ b/R/penvs_userBgExtent.R @@ -34,7 +34,7 @@ #' userBgBuf = 0.2, occs = occs) #' #' @return This function returns a SpatialPolygons object with the user -#' provided shape (+ a buffer is userBgBuf >0). The polygon will be at least +#' provided shape (+ a buffer if userBgBuf >0). The polygon will be at least #' large enough to contain all occurrences. #' @author Jamie Kass #' @author Gonzalo E. Pinilla-Buitrago @@ -79,8 +79,13 @@ penvs_userBgExtent <- function(bgShp_path, bgShp_name, userBgBuf, occs, } if (userBgBuf >= 0) { - bgExt <- rgeos::gBuffer(bgExt, width = userBgBuf) - bgExt <- methods::as(bgExt, "SpatialPolygonsDataFrame") + bgExt <- sf::st_as_sf(bgExt) + bgExt <- sf::st_buffer(bgExt, dist = userBgBuf) + bgExt <- sf::as_Spatial(bgExt) + } else { + bgExt <- sf::st_as_sf(bgExt) + bgExt <- sf::st_buffer(bgExt, dist = userBgBuf) + bgExt <- sf::as_Spatial(bgExt) } ### Points outside polygon diff --git a/R/xfer_draw.R b/R/xfer_draw.R index e4ed133c..c0819750 100644 --- a/R/xfer_draw.R +++ b/R/xfer_draw.R @@ -29,7 +29,7 @@ #' polygonTest <- xfer_draw(polyXfXY = userDrawPoly, polyXfID, #' drawXfBuf) #' -#' @return This functions returns a SpatialPolygonsDataFrame based on the user +#' @return This functions returns a SpatialPolygons object based on the user #' specified coordinates (drawn on map). This SpatialPolygonsDataFrame may be #' larger than specified if drawBgBuf > 0. @@ -41,8 +41,9 @@ xfer_draw <- function(polyXfXY, polyXfID, drawXfBuf, logger = NULL, spN = NULL) { newPoly <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(polyXfXY)), ID = polyXfID))) - bgExt <- rgeos::gBuffer(newPoly, width = drawXfBuf) - bgExt <- methods::as(bgExt, "SpatialPolygonsDataFrame") + newPoly.sf <- sf::st_as_sf(newPoly) + bgExt <- sf::st_buffer(newPoly.sf, dist = drawXfBuf) + bgExt <- sf::as_Spatial(bgExt) if (drawXfBuf == 0) { logger %>% writeLog(hlSpp(spN), 'Draw polygon without buffer.') } else { diff --git a/R/xfer_userExtent.R b/R/xfer_userExtent.R index c04b0f91..fa8dd66d 100644 --- a/R/xfer_userExtent.R +++ b/R/xfer_userExtent.R @@ -71,15 +71,19 @@ xfer_userExtent <- function(bgShp_path, bgShp_name, userBgBuf, return() } - if (userBgBuf >= 0) { - bgExt <- rgeos::gBuffer(bgExt, width = userBgBuf) - bgExt <- methods::as(bgExt, "SpatialPolygonsDataFrame") - } if (userBgBuf > 0) { + bgExt <- sf::st_as_sf(bgExt) + bgExt <- sf::st_buffer(bgExt, dist = userBgBuf) + bgExt <- sf::as_Spatial(bgExt) logger %>% writeLog( hlSpp(spN), 'Transferring extent user-defined polygon buffered by ', userBgBuf, ' degrees.') + } else if (userBgBuf < 0) { + logger %>% + writeLog(type = 'error', + 'Change buffer distance to a positive value.') + return() } else { logger %>% writeLog( hlSpp(spN), diff --git a/README.md b/README.md index 507c95c0..fbeab92d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![R-CMD-check](https://github.com/wallaceEcoMod/wallace/workflows/R-CMD-check/badge.svg)](https://github.com/wallaceEcoMod/wallace/actions) [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![CRAN version](http://www.r-pkg.org/badges/version/wallace)](https://CRAN.R-project.org/package=wallace) [![downloads](https://cranlogs.r-pkg.org:443/badges/grand-total/wallace?color=orange)](https://cranlogs.r-pkg.org:443/badges/grand-total/wallace?color=orange) -# Wallace (v2.0.6) +# Wallace (v2.1.0) *Wallace* is a modular platform for reproducible modeling of species niches and distributions, written in R. The application guides users through a complete analysis, from the acquisition of data to visualizing model predictions on an interactive map, thus bundling complex workflows into a single, streamlined interface. @@ -27,7 +27,7 @@ run_wallace() Please make sure you have installed the latest versions of both R (Mac OS, Windows) and RStudio (Mac OS / Windows: choose the free version). #### How to run Maxent with maxent.jar -*Wallace* v2.0.6 includes two options to run Maxent models: maxnet and maxent.jar. The former, which is an R implementation and fits the model with the package `glmnet`, is now the default and does not require the package `rJava` (see Phillips et al. 2017). The latter, which is the Java implementation, runs the `maxent()` function in the package `dismo`. This function requires the user to place the `maxent.jar` file in the `/java` directory of the `dismo` package root folder. You can download Maxent here, and locate `maxent.jar`, which is the Maxent program itself, in the downloaded folder. You can find the directory path to `dismo/java` by running `system.file('java', package="dismo")` at the R console. Simply copy `maxent.jar` and paste it into this folder. If you try to run Maxent in *Wallace* without the file in place, you will get a warning message in the log window and Maxent will not run. +*Wallace* v2.1.0 includes two options to run Maxent models: maxnet and maxent.jar. The former, which is an R implementation and fits the model with the package `glmnet`, is now the default and does not require the package `rJava` (see Phillips et al. 2017). The latter, which is the Java implementation, runs the `maxent()` function in the package `dismo`. This function requires the user to place the `maxent.jar` file in the `/java` directory of the `dismo` package root folder. You can download Maxent here, and locate `maxent.jar`, which is the Maxent program itself, in the downloaded folder. You can find the directory path to `dismo/java` by running `system.file('java', package="dismo")` at the R console. Simply copy `maxent.jar` and paste it into this folder. If you try to run Maxent in *Wallace* without the file in place, you will get a warning message in the log window and Maxent will not run. ### Potential Issues diff --git a/inst/shiny/Rmd/text_about.Rmd b/inst/shiny/Rmd/text_about.Rmd index 01d0c99b..d8c89ba4 100644 --- a/inst/shiny/Rmd/text_about.Rmd +++ b/inst/shiny/Rmd/text_about.Rmd @@ -7,7 +7,7 @@ output: html_document logo -Welcome to *Wallace*, a flexible application for reproducible ecological modeling, built for community expansion. The current version of *Wallace* (v2.0.6) steps the user through a full niche/distribution modeling analysis, from data acquisition to visualizing results. +Welcome to *Wallace*, a flexible application for reproducible ecological modeling, built for community expansion. The current version of *Wallace* (v2.1.0) steps the user through a full niche/distribution modeling analysis, from data acquisition to visualizing results. The application is written in `R` with the web app development package `shiny`. Please find the stable version of *Wallace* on CRAN, and the development version on Github. We also maintain a *Wallace* website that has some basic info, links, and will be updated with tutorial materials in the near future. diff --git a/inst/shiny/Rmd/text_intro_tab.Rmd b/inst/shiny/Rmd/text_intro_tab.Rmd index c14c48f0..4d1cd6f5 100644 --- a/inst/shiny/Rmd/text_intro_tab.Rmd +++ b/inst/shiny/Rmd/text_intro_tab.Rmd @@ -5,7 +5,7 @@ output: html_document #### WORKFLOW -*Wallace* (v2.0.6) currently includes ten components, or steps of a possible workflow. Each component includes two or more modules, which are possible analyses for that step. +*Wallace* (v2.1.0) currently includes ten components, or steps of a possible workflow. Each component includes two or more modules, which are possible analyses for that step. **Components:** diff --git a/inst/shiny/Rmd/text_team.Rmd b/inst/shiny/Rmd/text_team.Rmd index edc59831..9f64ce6e 100644 --- a/inst/shiny/Rmd/text_team.Rmd +++ b/inst/shiny/Rmd/text_team.Rmd @@ -15,17 +15,20 @@ output: html_document gonzalo -Gonzalo E. Pinilla-Buitrago (co-lead developer) is a PhD candidate at the CUNY Graduate Center and City College of New York. +Gonzalo E. Pinilla-Buitrago (co-lead developer) received his PhD from the CUNY Graduate Center and City College of New York. He is currently a Postdoctoral Researcher at Yale University.
andrea -Andrea Paz (developer) received her PhD at CUNY Graduate Center and City College of New York and is now a Postdoctoral Researcher at the Crowther Lab in ETH Zürich. +Andrea Paz (developer) received her PhD at CUNY Graduate Center and City College of New York, after which she was a Postdoctoral Researcher at the Crowther Lab in ETH Zürich. She is now an Assistant Professor at the Biological Sciences Department, University of Montréal.
bethany -Bethany A. Johnson (developer) is a Master's student at the City College of New York. +Bethany A. Johnson (developer) received her MS in Biology from the City College of New York and is currently a Visiting Scientist at the Center for Biodiversity & Conservation at the American Museum of Natural History. +
+ +Daniel López Lozano (developer) is a Biodiversity Informatics Specialist at the American Museum of Natural History's Center for Biodiversity & Conservation.
valentina @@ -57,7 +60,7 @@ output: html_document mary -Mary E. Blair (co-manager) is the Director of Biodiversity Informatics Research at the Center for Biodiversity and Conservation at the American Museum of Natural History. +Mary E. Blair (co-manager) is the Director of Biodiversity Informatics Research at the Center for Biodiversity & Conservation at the American Museum of Natural History.
## Contributors @@ -74,7 +77,7 @@ Sarah Meenan (contributor) completed her undergraduate degree from the City Coll peteG -Peter J. Galante (contributor) was a Biodiversity Informatics Scientist at the Center for Biodiversity and Conservation at the American Museum of Natural History and now works as a Project Manager for Storke, LLC, a renewable energy company. +Peter J. Galante (contributor) was formerly a Biodiversity Informatics Scientist at the Center for Biodiversity & Conservation at the American Museum of Natural History and now works as a Project Manager for Storke, LLC, a renewable energy company.
brianM diff --git a/inst/shiny/Rmd/userReport_intro.Rmd b/inst/shiny/Rmd/userReport_intro.Rmd index aa0c4fab..0db7bac5 100644 --- a/inst/shiny/Rmd/userReport_intro.Rmd +++ b/inst/shiny/Rmd/userReport_intro.Rmd @@ -10,7 +10,7 @@ knit_engines$set(asis = function(options) { knitr::opts_chunk$set(message = FALSE, warning = FALSE, eval = FALSE) ``` -Please find below the R code history from your *Wallace* v2.0.6 session. +Please find below the R code history from your *Wallace* v2.1.0 session. You can reproduce your session results by running this R Markdown file in RStudio. @@ -25,7 +25,7 @@ Wallace uses the following R packages that must be installed and loaded before s library(spocc) library(spThin) library(dismo) -library(rgeos) +library(sf) library(ENMeval) library(wallace) ``` diff --git a/inst/shiny/modules/occs_queryDb.md b/inst/shiny/modules/occs_queryDb.md index f8589fb0..ff1c50fb 100644 --- a/inst/shiny/modules/occs_queryDb.md +++ b/inst/shiny/modules/occs_queryDb.md @@ -6,11 +6,11 @@ Over the past two decades, the worldwide biodiversity informatics community has **IMPLEMENTATION** -By default, this module relies on the R package `spocc`, which provides streamlined access to many species occurrence databases, some of which aggregate data from myriad providers (e.g., individual museums or citizen-science initiatives) (Chamberlain et al. 2021). Currently, users can choose among two of the largest databases: GBIF and VertNet. Note that as implemented at present, users must choose only one of these databases, and any later download overwrites previous ones. +By default, this module relies on the R package `spocc`, which provides streamlined access to many species occurrence databases, some of which aggregate data from myriad providers (e.g., individual museums or citizen-science initiatives) (Chamberlain et al. 2021). Currently, users can choose among three of the largest databases: GBIF, VertNet, and BIEN. Note that as implemented at present, users must choose only one of these databases, and any later download overwrites previous ones. When GBIF has been selected, an alternative option exists to receive data source citations in addition to the records themselves. In this case, the module will use the R package `occCite` instead of `spocc`. Whereas `spocc` uses the `occ_search()` function from the `rgbif` package to perform a streamlined search of the GBIF database (Chamberlain et al. 2021), the `occCite` package instead uses `occ_download()` from the `rgbif` package (Owens et al. 2021). While this requires the user to enter their GBIF login information (which must be set up beforehand), the search has two advantages. First, it returns a DOI that can be used to cite the downloaded dataset when publishing manuscripts and other descriptions of research results. Second, it has no hard limit on the number of occurrences that can be obtained (which is set at 100,000 in searches conducted with `occ_search()`. -For all options in this module, records used in downstream analyses in *Wallace* are filtered to remove those without georeferences (latitude/longitude coordinates) and that have exact duplicate coordinates of other records (including the same number of decimal places). The "Occurrences" tab displays all the filtered records with several key fields: scientific_name, longitude, latitude, country, state_province, locality, year, record_type, catalog_number, institution_code, elevation, (standard field names from GBIF), and uncertainty. The records are available for download as a .csv file with all original fields and include records without georeferences, or as the cleaned table shown in the “Occurrences” tab. Additionally, the user can choose to retain only records that have an estimate of the uncertainty of the georeference, which can be critical for assessing whether or not the record is of sufficient quality for a given analysis (Anderson et al. 2020). +For all options in this module, records are filtered to include presences only (excuding absence data). Also, records used in downstream analyses in *Wallace* are filtered to remove those without georeferences (latitude/longitude coordinates) and that have exact duplicate coordinates of other records (including the same number of decimal places). The "Occurrences" tab displays all the filtered records with several key fields: scientific_name, longitude, latitude, country, state_province, locality, year, record_type, catalog_number, institution_code, elevation, (standard field names from GBIF), and uncertainty. The records are available for download as a .csv file with all original fields and include records without georeferences, or as the cleaned table shown in the “Occurrences” tab. Additionally, the user can choose to retain only records that have an estimate of the uncertainty of the georeference, which can be critical for assessing whether or not the record is of sufficient quality for a given analysis (Anderson et al. 2020). **REFERENCES** diff --git a/inst/shiny/modules/penvs_bgExtent.R b/inst/shiny/modules/penvs_bgExtent.R index d0874d05..0b9db46f 100644 --- a/inst/shiny/modules/penvs_bgExtent.R +++ b/inst/shiny/modules/penvs_bgExtent.R @@ -72,7 +72,7 @@ penvs_bgExtent_module_server <- function(input, output, session, common) { spp[[sp]]$procEnvs$bgExt <- bgExt # REFERENCES #### - knitcitations::citep(citation("rgeos")) + knitcitations::citep(citation("sf")) knitcitations::citep(citation("sp")) # METADATA #### diff --git a/inst/shiny/modules/penvs_bgExtent.md b/inst/shiny/modules/penvs_bgExtent.md index 62ed3f82..41f6bcc8 100644 --- a/inst/shiny/modules/penvs_bgExtent.md +++ b/inst/shiny/modules/penvs_bgExtent.md @@ -6,7 +6,7 @@ For niche/distribution modeling approaches that compare the environments associa **IMPLEMENTATION** -This module relies on important functions from the R packages `sp` (for defining spatial objects) and `rgeos` (for buffering spatial objects). +This module relies on important functions from the R packages `sp` (for defining spatial objects) and `sf` (for buffering spatial objects). In this module, *Wallace* provides three simple ways to delimit a study region, by: 1) bounding box (rectangle with most the extreme coordinates in the four cardinal directions as vertices), 2) minimum convex polygon (a convex shape drawn around localities with minimized area), or 3) buffers around occurrence points. For each of these options, users can specify a buffer distance (in degrees; i.e. not meters). *Wallace* then masks the environmental grids by the resulting polygon. Users can download the masked grids as three raster grid formats (.asc, .grd, and .tif). diff --git a/inst/shiny/modules/penvs_bgExtent.yml b/inst/shiny/modules/penvs_bgExtent.yml index a7c7602d..5a483838 100644 --- a/inst/shiny/modules/penvs_bgExtent.yml +++ b/inst/shiny/modules/penvs_bgExtent.yml @@ -2,4 +2,4 @@ component: "penvs" short_name: "Select Study Region" long_name: "Select Study Region by Extent" authors: "Jamie M. Kass, Bruno Vilela, Robert P. Anderson" -package: [sp, rgeos] +package: [sp, sf] diff --git a/inst/shiny/modules/penvs_drawBgExtent.md b/inst/shiny/modules/penvs_drawBgExtent.md index ec312299..aadd4b0b 100644 --- a/inst/shiny/modules/penvs_drawBgExtent.md +++ b/inst/shiny/modules/penvs_drawBgExtent.md @@ -8,17 +8,15 @@ This module allows users to use the polygon-drawing tool to delineate the study The R package `leaflet.extras` (Karambelkar et al. 2018) provides a drawing tool plugin to the `leaflet` map (Cheng et al. 2022) for this module, which allows users to draw a polygon to specify the study region. The polygon-drawing tool icon is located underneath the zoom in/out buttons on the map. If a mistake is made while drawing, the last point can be deleted, or the whole drawing can be cleared. To finish, click the first point to close the shape. -Also, this module relies on `rgeos` (Bivand et al. 2021) for buffering spatial objects. A buffer can be applied (in degrees) to the drawn polygon before moving on to Step 2) Sample Background Points. +Also, this module relies on `sf` (Pebesma 2018) for buffering spatial objects. A buffer can be applied (in degrees) to the drawn polygon before moving on to Step 2) Sample Background Points. Wallace then masks the environmental grids by the resulting polygon. Users can download the masked grids in three raster grid formats (.asc, .grd, and .tif). **REFERENCES** -Bivand, R., Rundel, C., Pebesma, E., Stuetz, R., Hufthammer, K.O., Giraudoux, P., Davis, M, & Santilli, S. (2021). rgeos: Interface to Geometry Engine - Open Source ('GEOS'). CRAN. R package Version 0.5-0.9. -CRAN - Cheng, et al. (2022). leaflet: Create Interactive Web Maps with the JavaScript 'Leaflet' Library. R package Version 2.1. GitHub Karambelkar, et al. (2018). leaflet.extras: Extra Functionality for 'leaflet' Package. R package Version 1.0. GitHub +Pebesma, E., 2018. Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal 10 (1), 439-446, DOI:10.32614/RJ-2018-009. diff --git a/inst/shiny/modules/rep_refPackages.yml b/inst/shiny/modules/rep_refPackages.yml index f2b07ccc..c686e5e8 100644 --- a/inst/shiny/modules/rep_refPackages.yml +++ b/inst/shiny/modules/rep_refPackages.yml @@ -1,5 +1,5 @@ component: "rep" short_name: "Reference Packages" long_name: "List Reference Packages" -authors: "Gonzalo E. Pinilla-Buitrago, Bethany Johnson, Robert P. Anderson" +authors: "Gonzalo E. Pinilla-Buitrago, Bethany A. Johnson, Robert P. Anderson" package: [RefManageR, knitcitations] diff --git a/inst/shiny/modules/xfer_area.R b/inst/shiny/modules/xfer_area.R index 4d39629e..358acf41 100644 --- a/inst/shiny/modules/xfer_area.R +++ b/inst/shiny/modules/xfer_area.R @@ -45,7 +45,7 @@ xfer_area_module_ui <- function(id) { actionButton(ns('goTransferArea'), "Transfer"), tags$hr(class = "hrDashed"), actionButton(ns("goResetXfer"), "Reset", class = 'butReset'), - strong(" transferion extent ") + strong(" transfer extent ") ) } @@ -117,13 +117,22 @@ xfer_area_module_server <- function(input, output, session, common) { input$userXfBuf, logger, spN = curSp()) # ERRORS #### # Check that the extents of raster and transfer extent intersects - if (!rgeos::gIntersects(polyXf, - methods::as(raster::extent(envs()), - 'SpatialPolygons'))) { + polyXf_sfc <- sf::st_as_sfc(polyXf) #convert poly to sfc + envs_ext <- methods::as(raster::extent(envs()),'SpatialPolygons') + envs_sfc <- sf::st_as_sfc(envs_ext) #convert envs to sfc + #set crs to match + if (sf::st_crs(polyXf_sfc) != sf::st_crs(envs_sfc)) { + sf::st_crs(polyXf_sfc) <- sf::st_crs(envs_sfc) logger %>% - writeLog(type = 'error', 'Extents do not overlap') + writeLog(type = 'error', 'CRS was automatically set to match environmental variables.') return() } + if (!sf::st_intersects(polyXf_sfc, envs_sfc, sparse = FALSE)[1,1]) { + logger %>% + writeLog(type = 'error', 'Extents do not overlap.') + return() + } + # METADATA #### spp[[curSp()]]$rmm$code$wallace$XfBuff <- input$userXfBuf # get extensions of all input files @@ -158,15 +167,16 @@ xfer_area_module_server <- function(input, output, session, common) { return() } if (is.null(spp[[curSp()]]$transfer$xfExt)) { - logger %>% writeLog(type = 'error', 'Select transferion extent first.') + logger %>% writeLog(type = 'error', 'Select transfer extent first.') return() } # Check that the extents of raster and transfer extent intersects - if (!rgeos::gIntersects(spp[[curSp()]]$transfer$xfExt, - methods::as(raster::extent(envs()), - 'SpatialPolygons'))) { + Xfer_sfc <- sf::st_as_sfc(spp[[curSp()]]$transfer$xfExt) #convert xfrExt to sfc + envs_ext <- methods::as(raster::extent(envs()),'SpatialPolygons') + envs_sfc <- sf::st_as_sfc(envs_ext) #convert envs to sfc + if (!sf::st_intersects(Xfer_sfc, envs_sfc, sparse = FALSE)[1,1]) { logger %>% - writeLog(type = 'error', 'Extents do not overlap') + writeLog(type = 'error', 'Extents do not overlap.') return() } @@ -233,11 +243,11 @@ xfer_area_module_server <- function(input, output, session, common) { thr <- stats::quantile(occPredVals, probs = input$trainPresQuantile) } xferAreaThr <- xferArea > thr - logger %>% writeLog(hlSpp(curSp()), "Transferion of model to new area with threshold ", + logger %>% writeLog(hlSpp(curSp()), "Transfer of model to new area with threshold ", input$threshold, ' (', formatC(thr, format = "e", 2), ').') } else { xferAreaThr <- xferArea - logger %>% writeLog(hlSpp(curSp()), "Transferion of model to new area with ", + logger %>% writeLog(hlSpp(curSp()), "Transfer of model to new area with ", predType, ' output.') } raster::crs(xferAreaThr) <- raster::crs(envs()) @@ -295,12 +305,12 @@ xfer_area_module_server <- function(input, output, session, common) { common$update_component(tab = "Map") }) - # Reset Transferion Extent button functionality + # Reset Transfer Extent button functionality observeEvent(input$goResetXfer, { spp[[curSp()]]$polyXfXY <- NULL spp[[curSp()]]$polyXfID <- NULL spp[[curSp()]]$transfer <- NULL - logger %>% writeLog("Reset transferion extent.") + logger %>% writeLog("Reset transfer extent.") }) return(list( @@ -337,7 +347,7 @@ xfer_area_module_map <- function(map, common) { circleOptions = FALSE, markerOptions = FALSE, circleMarkerOptions = FALSE, editOptions = leaflet.extras::editToolbarOptions() ) - # Add just transferion Polygon + # Add just transfer Polygon req(spp[[curSp()]]$transfer$xfExt) polyXfXY <- spp[[curSp()]]$transfer$xfExt@polygons[[1]]@Polygons if(length(polyXfXY) == 1) { @@ -374,7 +384,7 @@ xfer_area_module_map <- function(map, common) { values = mapXferVals, layerId = 'xfer', labFormat = reverseLabel(2, reverse_order = TRUE)) } - # map model prediction raster and transferion polygon + # map model prediction raster and transfer polygon map %>% clearMarkers() %>% clearShapes() %>% removeImage('xferRas') %>% addRasterImage(mapXfer(), colors = rasPal, opacity = 0.7, layerId = 'xferRas', group = 'xfer', method = "ngb") @@ -398,9 +408,9 @@ xfer_area_module_rmd <- function(species) { polyXfID_rmd = if(!is.null(species$rmm$code$wallace$drawExtPolyXfCoords)){ species$polyXfID} else {0}, BgBuf_rmd = species$rmm$code$wallace$XfBuff, - ##Determine the type of transferion extent to use correct RMD function + ##Determine the type of transfer extent to use correct RMD function xfer_area_extent_knit = !is.null(species$rmm$code$wallace$userXfShpParams), - ##Use of threshold for transferion + ##Use of threshold for transfer xfer_area_threshold_knit = !is.null(species$rmm$prediction$transfer$environment1$thresholdSet), xfer_thresholdRule_rmd = species$rmm$prediction$transfer$environment1$thresholdRule, xfer_threshold_rmd = if (!is.null(species$rmm$prediction$transfer$environment1$thresholdSet)){ diff --git a/inst/shiny/modules/xfer_time.R b/inst/shiny/modules/xfer_time.R index 06c46cbe..47b4e819 100644 --- a/inst/shiny/modules/xfer_time.R +++ b/inst/shiny/modules/xfer_time.R @@ -223,7 +223,7 @@ xfer_time_module_server <- function(input, output, session, common) { polyXf <- spp[[curSp()]]$procEnvs$bgExt logger %>% writeLog( hlSpp(curSp()), - 'Transferion extent equal to current extent region.') + 'Transfer extent equal to current extent region.') } # LOAD INTO SPP #### spp[[curSp()]]$transfer$xfExt <- polyXf @@ -252,7 +252,6 @@ xfer_time_module_server <- function(input, output, session, common) { 'resolutions >30 arc seconds.')) return() } - if(!all(names(envs()) %in% paste0('bio', sprintf("%02d", 1:19)))) { nonBios <- names(envs())[!names(envs()) %in% paste0('bio', sprintf("%02d", 1:19))] logger %>% @@ -262,6 +261,18 @@ xfer_time_module_server <- function(input, output, session, common) { "). You can not transfer to a New Time.") return() } + if(input$selTime == "") { + logger %>% writeLog(type = 'error', "Please select transfer time period.") + return() + } + if(input$selGCM == "") { + logger %>% writeLog(type = 'error', "Please select global circulation model.") + return() + } + if(input$selRCP == "") { + logger %>% writeLog(type = 'error', "Please select RCP.") + return() + } # DATA #### if (input$selTimeVar == 'worldclim') { @@ -310,11 +321,12 @@ xfer_time_module_server <- function(input, output, session, common) { # ERRORS #### # Check that the extents of raster and extent of transfer intersects - if (!rgeos::gIntersects(spp[[curSp()]]$transfer$xfExt, - methods::as(raster::extent(xferTimeEnvs), - 'SpatialPolygons'))) { + Xfer_sfc <- sf::st_as_sfc(spp[[curSp()]]$transfer$xfExt) #convert poly to sfc + xferTimeEnvs_sp <- methods::as(raster::extent(xferTimeEnvs),'SpatialPolygons') + xferTimeEnvs_sfc <- sf::st_as_sfc(xferTimeEnvs_sp) #convert xfer envs to sfc + if (!sf::st_intersects(Xfer_sfc, xferTimeEnvs_sfc, sparse = FALSE)[1,1]) { logger %>% - writeLog(type = 'error', 'Extents do not overlap') + writeLog(type = 'error', 'Extents do not overlap.') return() } @@ -359,13 +371,13 @@ xfer_time_module_server <- function(input, output, session, common) { } xferTimeThr <- xferTime > thr if (input$selTimeVar == 'worldclim') { - logger %>% writeLog(hlSpp(curSp()), "Transferion of model to ", paste0('20', input$selTime), + logger %>% writeLog(hlSpp(curSp()), "Transfer of model to ", paste0('20', input$selTime), ' with threshold ', input$threshold, ' (', formatC(thr, format = "e", 2), ") for GCM ", GCMlookup[input$selGCM], " under RCP ", as.numeric(input$selRCP)/10.0, ".") } else if (input$selTimeVar == 'ecoclimate') { - logger %>% writeLog(hlSpp(curSp()), "Transferion of model to ", input$xfScenario, + logger %>% writeLog(hlSpp(curSp()), "Transfer of model to ", input$xfScenario, ' with threshold ', input$threshold, ' (', formatC(thr, format = "e", 2), ") for GCM ", input$xfAOGCM, ".") @@ -373,11 +385,11 @@ xfer_time_module_server <- function(input, output, session, common) { } else { xferTimeThr <- xferTime if (input$selTimeVar == 'worldclim') { - logger %>% writeLog(hlSpp(curSp()), "Transferion of model to ", paste0('20', input$selTime), + logger %>% writeLog(hlSpp(curSp()), "Transfer of model to ", paste0('20', input$selTime), ' with ', predType, " output for GCM ", GCMlookup[input$selGCM], " under RCP ", as.numeric(input$selRCP)/10.0, ".") } else if (input$selTimeVar == 'ecoclimate') { - logger %>% writeLog(hlSpp(curSp()), "Transferion of model to ", input$xfScenario, + logger %>% writeLog(hlSpp(curSp()), "Transfer of model to ", input$xfScenario, ' with ', predType, " output for GCM ", input$xfAOGCM, ".") } } @@ -476,7 +488,7 @@ xfer_time_module_server <- function(input, output, session, common) { common$update_component(tab = "Map") }) - # Reset Transferion Extent button functionality + # Reset Transfer Extent button functionality observeEvent(input$goResetXfer, { spp[[curSp()]]$polyXfXY <- NULL spp[[curSp()]]$polyXfID <- NULL diff --git a/inst/shiny/modules/xfer_user.R b/inst/shiny/modules/xfer_user.R index a3894076..d79fd77e 100644 --- a/inst/shiny/modules/xfer_user.R +++ b/inst/shiny/modules/xfer_user.R @@ -227,11 +227,12 @@ xfer_user_module_server <- function(input, output, session, common) { # ERRORS #### # Check that the extents of raster and extent of transfer intersects - if (!rgeos::gIntersects(spp[[curSp()]]$transfer$xfExt, - methods::as(raster::extent(userXferEnvs), - 'SpatialPolygons'))) { + Xfer_sfc <- sf::st_as_sfc(spp[[curSp()]]$transfer$xfExt) #convert poly to sfc + userXferEnvs_sp <- methods::as(raster::extent(userXferEnvs),'SpatialPolygons') + userXferEnvs_sfc <- sf::st_as_sfc(userXferEnvs_sp) #convert user envs to sfc + if (!sf::st_intersects(Xfer_sfc, userXferEnvs_sfc, sparse = FALSE)[1,1]) { logger %>% - writeLog(type = 'error', 'Extents do not overlap') + writeLog(type = 'error', 'Extents do not overlap.') return() } diff --git a/tests/testthat/test_penvs_bgExtent.R b/tests/testthat/test_penvs_bgExtent.R index c7b5b0ce..3496a9b7 100644 --- a/tests/testthat/test_penvs_bgExtent.R +++ b/tests/testthat/test_penvs_bgExtent.R @@ -45,15 +45,15 @@ test_that("error checks", { # buffer == 0 while using Point Buffers as background extent expect_error(penvs_bgExtent(occs , bgSel = bPoint, bgBuf = 0), - 'Change buffer distance to positive or negative value.') + 'Change buffer distance to a positive value.') }) ### test output features test_that("output type checks", { # the output is a SpatialPolygonsDataFrame - expect_is(bgExt1, "SpatialPolygonsDataFrame") - expect_is(bgExt2, "SpatialPolygonsDataFrame") - expect_is(bgExt3, "SpatialPolygonsDataFrame") + expect_is(bgExt1, "SpatialPolygons") + expect_is(bgExt2, "SpatialPolygons") + expect_is(bgExt3, "SpatialPolygons") # the area of each type of the background extents is different expect_false(raster::area(bgExt1) == raster::area(bgExt2)) expect_false(raster::area(bgExt1) == raster::area(bgExt3)) diff --git a/tests/testthat/test_penvs_drawBgExtent.R b/tests/testthat/test_penvs_drawBgExtent.R index 67d3f848..f3a3033b 100644 --- a/tests/testthat/test_penvs_drawBgExtent.R +++ b/tests/testthat/test_penvs_drawBgExtent.R @@ -50,8 +50,8 @@ test_that("error checks", { ### test output features test_that("output type checks", { # the output is a SpatialPolygons - expect_is(drawBgBf, "SpatialPolygonsDataFrame") - expect_is(drawBg, "SpatialPolygonsDataFrame") + expect_is(drawBgBf, "SpatialPolygons") + expect_is(drawBg, "SpatialPolygons") # the area of background buffered is different from the one not buffered expect_true(raster::area(drawBgBf) > raster::area(drawBg)) ## check if all the records are within the drawn polygon diff --git a/tests/testthat/test_xfer_draw.R b/tests/testthat/test_xfer_draw.R index 70f97a6b..d5e59a12 100644 --- a/tests/testthat/test_xfer_draw.R +++ b/tests/testthat/test_xfer_draw.R @@ -20,8 +20,8 @@ polygonTestZero <- xfer_draw(polyXfXY = userDrawPoly, polyXfID, test_that("output type checks", { # the drawn polygon does not include all localities - expect_is(polygonTest,'SpatialPolygonsDataFrame') - expect_is(polygonTestZero,'SpatialPolygonsDataFrame') + expect_is(polygonTest,'SpatialPolygons') + expect_is(polygonTestZero,'SpatialPolygons') ###the extent of the polygon for buffer = 0 corresponds to maximum provided expect_equal(sp::bbox(polygonTestZero)[1,1],min(longitude)) expect_equal(sp::bbox(polygonTestZero)[2,1],min(latitude)) diff --git a/vignettes/module-addition.Rmd b/vignettes/module-addition.Rmd index 5fa880bb..412cb2ea 100644 --- a/vignettes/module-addition.Rmd +++ b/vignettes/module-addition.Rmd @@ -1,6 +1,6 @@ --- title: "How to write a module in Wallace" -author: "Gonzalo Pinilla-Buitrago, Jamie M. Kass, Siew Fong Chen, Peter Galante, Bethany Johnson, Dean Attali" +author: "Gonzalo Pinilla-Buitrago, Jamie M. Kass, Siew Fong Chen, Peter Galante, Bethany A. Johnson, Dean Attali" date: "April 19, 2022" output: rmarkdown::html_vignette vignette: > diff --git a/vignettes/tutorial-v2-esp.Rmd b/vignettes/tutorial-v2-esp.Rmd index 351a2c1a..3427f3c1 100644 --- a/vignettes/tutorial-v2-esp.Rmd +++ b/vignettes/tutorial-v2-esp.Rmd @@ -2,7 +2,7 @@ title: "Tutorial de Wallace Aplicación de modelado Ecológico v2.0" author: - Bethany A. Johnson, Gonzalo E. Pinilla-Buitrago, Andrea Paz, Jamie M. Kass, Sarah I. Meenan, Robert P. Anderson -- Traducción al español por Andrea Paz y Bethany Johnson +- Traducción al español por Andrea Paz y Bethany A. Johnson date: "2023-03-11" output: rmarkdown::html_vignette vignette: >