diff --git a/.Rbuildignore b/.Rbuildignore index 87a96b8..befc2b7 100755 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,5 @@ cran-comments.md ^appveyor\.yml$ ToDo.md ^\.github$ +^codecov\.yml$ +^\.covrignore$ diff --git a/.covrignore b/.covrignore new file mode 100644 index 0000000..46dc9ab --- /dev/null +++ b/.covrignore @@ -0,0 +1,3 @@ +R/zzz.R +inst/shiny/* +R/plot.model.R diff --git a/DESCRIPTION b/DESCRIPTION index d4c330d..ce7019f 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: SSDM Type: Package Title: Stacked Species Distribution Modelling -Version: 0.2.8.9002 +Version: 0.2.9 Author: Sylvain Schmitt, Robin Pouteau, Dimitri Justeau, Florian de Boissieu, Lukas Baumbach, Philippe Birnbaum Maintainer: Sylvain Schmitt URL: https://github.com/sylvainschmitt/SSDM @@ -34,7 +34,6 @@ Imports: scales (>= 1.0.0), shiny (>= 0.12.2), shinydashboard (>= 0.5.1), - shinyFiles (>= 0.7.0), spThin (>= 0.1.0), poibin (>= 1.3.0), foreach (>= 1.4.4), @@ -42,8 +41,9 @@ Imports: iterators (>= 1.0.10), itertools (>= 0.1-3), parallel (>= 3.5.2), - snow (>= 0.4-3), - leaflet (>= 2.2.0) + leaflet (>= 2.2.0), + magrittr (>= 2.0.3), + sdm (>= 1.1.8) Depends: R (>= 3.2.2) Collate: @@ -77,12 +77,13 @@ Collate: 'stack_modelling.R' 'stacking.R' 'update.stack.R' + 'utils-pipe.R' 'zzz.R' Suggests: testthat, knitr, rmarkdown, - sdm + shinyFiles RoxygenNote: 7.2.3 VignetteBuilder: knitr, diff --git a/NAMESPACE b/NAMESPACE index 0e82e68..82468c0 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export("%>%") export(ensemble) export(ensemble_modelling) export(evaluate) @@ -63,6 +64,7 @@ importFrom(leaflet,colorNumeric) importFrom(leaflet,leaflet) importFrom(leaflet,leafletOutput) importFrom(leaflet,renderLeaflet) +importFrom(magrittr,"%>%") importFrom(mgcv,gam) importFrom(mgcv,gam.control) importFrom(nnet,nnet) @@ -103,6 +105,7 @@ importFrom(reshape2,melt) importFrom(rpart,rpart) importFrom(rpart,rpart.control) importFrom(scales,muted) +importFrom(sdm,calibration) importFrom(sf,st_as_sf) importFrom(sf,st_buffer) importFrom(shiny,actionButton) @@ -115,6 +118,7 @@ importFrom(shiny,fluidRow) importFrom(shiny,h1) importFrom(shiny,h2) importFrom(shiny,h3) +importFrom(shiny,htmlOutput) importFrom(shiny,icon) importFrom(shiny,incProgress) importFrom(shiny,observeEvent) @@ -158,6 +162,7 @@ importFrom(stats,rbinom) importFrom(stats,runif) importFrom(stats,sd) importFrom(stats,var) +importFrom(utils,capture.output) importFrom(utils,lsf.str) importFrom(utils,read.csv) importFrom(utils,read.csv2) diff --git a/NEWS.md b/NEWS.md index e11ab05..2aca905 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,12 +1,12 @@ NEWS ================ -SSDM 0.2.8.9001 +SSDM 0.2.9 =============== bug fixes: - totally removing rgdal following r-spatial evolution -- moving from sp to sf following r-spatial evolution +- moving from sp to sf and leaflet following r-spatial evolution SSDM 0.2.8.9000 =============== diff --git a/R/evaluate.R b/R/evaluate.R index ae8d9ec..0a97ec0 100755 --- a/R/evaluate.R +++ b/R/evaluate.R @@ -7,6 +7,7 @@ #' @importFrom stats aggregate.data.frame cor glm glm.control rbinom runif sd var #' @importFrom utils lsf.str read.csv read.csv2 tail write.csv #' @importFrom raster reclassify rasterize extract stack +#' @importFrom sdm calibration NULL #' Evaluate diff --git a/R/get_model.R b/R/get_model.R index 0ed11dd..31ea88c 100755 --- a/R/get_model.R +++ b/R/get_model.R @@ -11,6 +11,7 @@ #' @importFrom e1071 svm #' @importFrom stats aggregate.data.frame cor glm glm.control rbinom runif sd var #' @importFrom utils lsf.str read.csv read.csv2 tail write.csv +#' @importFrom utils capture.output NULL setGeneric("get_model", function(obj, ...) { @@ -188,7 +189,7 @@ setMethod("get_model", "GBM.SDM", function(obj, gbm.args=list(), ...) { } # call GBM - model <- do.call(gbm, gbm.args) + capture.output(model <- do.call(gbm, gbm.args), file = nullfile()) return(model) }) diff --git a/R/mapDiversity.R b/R/mapDiversity.R index 89874d7..66f59a5 100755 --- a/R/mapDiversity.R +++ b/R/mapDiversity.R @@ -2,6 +2,7 @@ #' @importFrom raster raster stack reclassify mask calc overlay values rasterize rasterToPoints values<- Which setValues #' @importFrom stats lm optim #' @importFrom poibin dpoibin +#' @importFrom sf st_as_sf NULL #' Map Diversity @@ -191,7 +192,7 @@ setMethod("mapDiversity", "Stacked.SDM", function(obj, method, rep.B = 1000, Richness <- reclassify(obj@esdms[[1]]@projection, c(-Inf, Inf, 0)) for (i in seq_len(length(obj@esdms))) Richness <- Richness + rasterize( - SpatialPoints(obj@esdms[[i]]@data[1:2]), + sf::st_as_sf(obj@esdms[[i]]@data[1:2], coords = c("X", "Y")), Richness, field = obj@esdms[[i]]@data$Presence, background = 0) if (all(values(Richness) %in% c(0, 1, NA))) diff --git a/R/plot.model.R b/R/plot.model.R index 6a839cf..ef7b975 100755 --- a/R/plot.model.R +++ b/R/plot.model.R @@ -1,6 +1,6 @@ #' @include Algorithm.SDM.R Ensemble.SDM.R Stacked.SDM.R #' @importFrom raster stack crop extent aggregate reclassify -#' @importFrom shiny h1 h2 h3 p reactiveValues observeEvent icon brushOpts shinyApp +#' @importFrom shiny h1 h2 h3 p reactiveValues observeEvent icon brushOpts shinyApp htmlOutput #' @importFrom shiny fluidPage fluidRow tabPanel actionButton #' @importFrom shiny selectInput sliderInput radioButtons checkboxInput checkboxGroupInput #' @importFrom shiny textOutput uiOutput plotOutput dataTableOutput tableOutput diff --git a/R/utils-pipe.R b/R/utils-pipe.R new file mode 100644 index 0000000..fd0b1d1 --- /dev/null +++ b/R/utils-pipe.R @@ -0,0 +1,14 @@ +#' Pipe operator +#' +#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +#' +#' @name %>% +#' @rdname pipe +#' @keywords internal +#' @export +#' @importFrom magrittr %>% +#' @usage lhs \%>\% rhs +#' @param lhs A value or the magrittr placeholder. +#' @param rhs A function call using the magrittr semantics. +#' @return The result of calling `rhs(lhs)`. +NULL diff --git a/README.md b/README.md index 7093b8a..00041fb 100755 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ SSDM: Stacked species distribution modelling [![R-CMD-check](https://github.com/sylvainschmitt/SSDM/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sylvainschmitt/SSDM/actions/workflows/R-CMD-check.yaml) [![Downloads](http://cranlogs.r-pkg.org/badges/SSDM?color=brightgreen)](http://www.r-pkg.org/pkg/SSDM) -[![Coverage Status](https://img.shields.io/codecov/c/github/sylvainschmitt/SSDM/master.svg)](https://codecov.io/github/sylvainschmitt/SSDM?branch=master) [![Research software impact](http://depsy.org/api/package/cran/SSDM/badge.svg)](http://depsy.org/package/r/SSDM) [![Gitter](https://badges.gitter.im/S-SDM/community.svg)](https://gitter.im/S-SDM/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +[![Codecov test coverage](https://codecov.io/gh/sylvainschmitt/SSDM/branch/master/graph/badge.svg)](https://app.codecov.io/gh/sylvainschmitt/SSDM?branch=master) [![Research software impact](http://depsy.org/api/package/cran/SSDM/badge.svg)](http://depsy.org/package/r/SSDM) [![Gitter](https://badges.gitter.im/S-SDM/community.svg)](https://gitter.im/S-SDM/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) SSDM is a package to map species richness and endemism based on stacked species distribution models (SSDM). Individual SDMs can be created using a single or multiple algorithms (ensemble SDMs). For each species, an SDM can yield a habitat suitability map, a binary map, a between-algorithm variance map, and can assess variable importance, algorithm accuracy, and between-algorithm correlation. Methods to stack individual SDMs include summing individual probabilities and thresholding then summing. Thresholding can be based on a specific evaluation metric or by drawing repeatedly from a Bernouilli distribution. The SSDM package also provides a user-friendly interface `gui`. diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true diff --git a/cran-comments.md b/cran-comments.md index e4b9d22..543f47a 100755 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,18 +1,23 @@ ## Test environments -* local Ubuntu 16.04 LTS, R 3.6.0 -* Travis CI Ubuntu 14.04.5 LTS, R-release -* R-hub Fedora Linux, R-devel, clang -* R-hub Ubuntu Linux 16.04 LTS, R-release -* R-hub Windows Server 2008 R2 SP1, R-devel -* Win-builder Windows, R-4.0.0 +* local Ubuntu 22.04 LTS, R 4.3.1 +* GitHub Actions Ubuntu 20.04 LTS, R-release ## R CMD check results -There were no NOTEs, ERRORs or WARNINGs. +There were no ERRORs or WARNINGs. -## Resubmission +There was one NOTE: + + Imports includes 24 non-default packages. + Importing from so many packages makes the package vulnerable to any of + them becoming unavailable. Move as many as possible to Suggests and + use conditionally. + +The fact that we quickly updated the package following several dependency +changes shows that we are able to assume all the needed dependencies. -This is a resubmission. In this version I have: +## Resubmission -# * Added stringsAsFactors = TRUE in read.csv2 from load_occ.R folowwing the new defaulot in R 4.0.0 +This is a resubmission. In this version I have removed rgdal and sp +from the package dependencies following r-spatial package archiving. diff --git a/man/pipe.Rd b/man/pipe.Rd new file mode 100644 index 0000000..1f8f237 --- /dev/null +++ b/man/pipe.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-pipe.R +\name{\%>\%} +\alias{\%>\%} +\title{Pipe operator} +\usage{ +lhs \%>\% rhs +} +\arguments{ +\item{lhs}{A value or the magrittr placeholder.} + +\item{rhs}{A function call using the magrittr semantics.} +} +\value{ +The result of calling `rhs(lhs)`. +} +\description{ +See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +} +\keyword{internal} diff --git a/tests/testthat/test_modelling.R b/tests/testthat/test_modelling.R index ea82851..8e01b0b 100755 --- a/tests/testthat/test_modelling.R +++ b/tests/testthat/test_modelling.R @@ -4,7 +4,7 @@ test_that('modelling function', { Occurrences <- subset(Occurrences, Occurrences$SPECIES == 'elliptica') available.algo <- available.algo <- c("GLM", "GAM", "MARS", "GBM", "CTA", "RF", "ANN", "SVM") for(i in available.algo){ - cat(paste("testing", i, "...\n")) + # cat(paste("testing", i, "...\n")) show_failure(SDM <- modelling(i, Occurrences, Env, Xcol = 'LONGITUDE', Ycol = 'LATITUDE', verbose = F)) expect_is(SDM, paste0(i,'.SDM')) } diff --git a/tests/testthat/test_parallel_ESDM.R b/tests/testthat/test_parallel_ESDM.R index 53f680c..b3f33e3 100644 --- a/tests/testthat/test_parallel_ESDM.R +++ b/tests/testthat/test_parallel_ESDM.R @@ -2,7 +2,7 @@ test_that('Ensemble parallelization', { data(Env) data(Occurrences) Occurrences <- subset(Occurrences, Occurrences$SPECIES == 'elliptica') - ESDM <- ensemble_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 10, + ESDM <- ensemble_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 1, Xcol = 'LONGITUDE', Ycol = 'LATITUDE', ensemble.thresh = c(0), verbose = FALSE, cores = 2, minimal.memory = TRUE, tmp = TRUE) diff --git a/tests/testthat/test_parallel_SSDM.R b/tests/testthat/test_parallel_SSDM.R index d4e63d5..e0c7c0b 100644 --- a/tests/testthat/test_parallel_SSDM.R +++ b/tests/testthat/test_parallel_SSDM.R @@ -2,7 +2,7 @@ test_that('Stack parallelization', { data(Env) data(Occurrences) for(i in c('species', 'algorithms', 'replicates')){ - SSDM <- stack_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 10, + SSDM <- stack_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 1, Xcol = 'LONGITUDE', Ycol = 'LATITUDE', Spcol = 'SPECIES', ensemble.thresh = c(0), method="pSSDM", uncertainty = TRUE, verbose = FALSE, cores = 2, parmode = i , minimal.memory = TRUE, tmp = FALSE) diff --git a/tests/testthat/test_project_ESDM.R b/tests/testthat/test_project_ESDM.R index 9ef384a..547ccf9 100644 --- a/tests/testthat/test_project_ESDM.R +++ b/tests/testthat/test_project_ESDM.R @@ -4,18 +4,18 @@ test_that('project Ensemble.SDM', { Occurrences <- subset(Occurrences, Occurrences$SPECIES == 'elliptica') ESDM <- ensemble_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 2, Xcol = 'LONGITUDE', Ycol = 'LATITUDE', ensemble.thresh = 0, verbose = FALSE) Env_new <- stack(Env[[1]]-1,Env[[2]],Env[[3]]) - - cat(paste("test sequential ESDM projection \n")) + + # cat(paste("test sequential ESDM projection \n")) ESDM_proj <- project(ESDM,Env_new,output.format='model') expect_is(ESDM_proj, 'Ensemble.SDM') expect_false(all(is.na(values(ESDM_proj@projection)))) - - cat(paste("test parallel ESDM projection \n")) + + # cat(paste("test parallel ESDM projection \n")) ESDM_proj <- project(ESDM,Env_new,output.format='model',cores=2,minimal.memory=TRUE) expect_is(ESDM_proj, 'Ensemble.SDM') expect_false(all(is.na(values(ESDM_proj@projection)))) - - cat(paste("test ESDM projection with raster output \n")) + + # cat(paste("test ESDM projection with raster output \n")) ESDM_proj <- project(ESDM,Env_new,output.format='rasters') expect_is(ESDM_proj, 'list') expect_is(ESDM_proj$projection, 'RasterLayer') diff --git a/tests/testthat/test_project_SSDM.R b/tests/testthat/test_project_SSDM.R index dfd9c25..dd8db65 100644 --- a/tests/testthat/test_project_SSDM.R +++ b/tests/testthat/test_project_SSDM.R @@ -5,19 +5,19 @@ test_that('project Stacked.SDM', { Xcol = 'LONGITUDE', Ycol = 'LATITUDE', Spcol = 'SPECIES', ensemble.thresh = 0, verbose = FALSE, cores = 0) - + Env_new <- stack(Env[[1]]-0.3,Env[[2]],Env[[3]]) - cat(paste("test sequential SSDM projection \n")) + # cat(paste("test sequential SSDM projection \n")) SSDM_proj <- project(SSDM,Env_new,output.format='model') expect_is(SSDM_proj, 'Stacked.SDM') expect_false(all(is.na(values(SSDM_proj@diversity.map)))) - - cat(paste("test parallel SSDM projection \n")) + + # cat(paste("test parallel SSDM projection \n")) SSDM_proj <- project(SSDM,Env_new,output.format='model',cores=2, minimal.memory=TRUE) expect_is(SSDM_proj, 'Stacked.SDM') expect_false(all(is.na(values(SSDM_proj@diversity.map)))) - - cat(paste("test SSDM projection with raster output \n")) + + # cat(paste("test SSDM projection with raster output \n")) SSDM_proj <- project(SSDM,Env_new,output.format='rasters') expect_is(SSDM_proj, 'list') expect_is(SSDM_proj$diversity.map, 'RasterLayer') diff --git a/vignettes/SSDM.Rmd b/vignettes/SSDM.Rmd index f559794..7cb647d 100755 --- a/vignettes/SSDM.Rmd +++ b/vignettes/SSDM.Rmd @@ -27,7 +27,7 @@ The workflow of the package ‘SSDM’ is based on three modelling levels: ### Environmental variables -In order to build species distribution models you will need environmental variables. Currently ‘SSDM’ uses all raster formats supported by the R package ‘rgdal’. The package ‘SSDM’ supports both continuous (e.g., climate maps, digital elevation models, bathymetric maps) and categorical environmental variables (e.g., land cover maps, soil type maps) as inputs. The package also allows normalizing environmental variables, which may be useful to improve the fit of certain algorithms (like artificial neural networks or support vector machines). +In order to build species distribution models you will need environmental variables. Currently ‘SSDM’ uses all raster formats supported by the R package ‘raster’. The package ‘SSDM’ supports both continuous (e.g., climate maps, digital elevation models, bathymetric maps) and categorical environmental variables (e.g., land cover maps, soil type maps) as inputs. The package also allows normalizing environmental variables, which may be useful to improve the fit of certain algorithms (like artificial neural networks or support vector machines). Rasters of environmental data need to have the same coordinate reference system while spatial extent and resolution of the environmental layers can differ. During processing, the package will deal with between-variables discrepancies in spatial extent and resolution by rescaling all environmental rasters to the smallest common spatial extent then upscaling them to the coarsest resolution.