diff --git a/R/eurobis_occurrences.R b/R/eurobis_occurrences.R index 51c9b43..e4e06c0 100644 --- a/R/eurobis_occurrences.R +++ b/R/eurobis_occurrences.R @@ -14,10 +14,10 @@ #' @param geometry a WKT geometry string or sf object with the region of interest. You can draw a polygon interactively #' with \code{\link{eurobis_map_draw}} #' @param dasid IMIS dataset unique identifier. See list of available datasets with \code{\link{eurobis_list_datasets}} -#' @param startdate Start date of occurrences. Format YYYY-MM-DD. -#' @param enddate End date of occurrences. Format YYYY-MM-DD. +#' @param start_date Start date of occurrences. Format YYYY-MM-DD. +#' @param end_date End date of occurrences. Format YYYY-MM-DD. #' @param aphiaid WoRMS taxon unique identifier. See \url{https://www.marinespecies.org/} and \url{https://docs.ropensci.org/worrms/} -#' @param scientificname Taxon name. It is matched with WoRMS on the fly. Ignored if aphiaid is provided. +#' @param scientific_name Taxon name. It is matched with WoRMS on the fly. Ignored if aphiaid is provided. #' @param functional_groups Functional groups available in WoRMS: See \code{eurobis::species_traits}. #' @param cites CITES Annex. See \code{eurobis::species_traits}. #' @param habitats_directive Habitats Directive Annex. See \code{eurobis::species_traits}. @@ -46,7 +46,7 @@ #' #' # Get occurrences from Zostera marina in the ecoregion Alboran Sea (MRGID 21897) #' # See also ?eurobis_list_regions -#' test <- eurobis_occurrences_full(mrgid = 21897, scientificname = "Zostera marina") +#' test <- eurobis_occurrences_full(mrgid = 21897, scientific_name = "Zostera marina") #' #' # Get zooplankton occurrences from the region of your choice #' # See ?eurobis_map_mr and ?eurobis::species_traits @@ -54,15 +54,15 @@ #' test <- eurobis_occurrences_basic(geometry = my_area, functional_groups = "zooplankton") #' #' # Get occurrences from the Continuous Plankton Recorder (dataset id 216) in January 2016 -#' test <- eurobis_occurrences_basic(dasid = 216, startdate = "2016-01-01", enddate = "2016-01-31") +#' test <- eurobis_occurrences_basic(dasid = 216, start_date = "2016-01-01", end_date = "2016-01-31") #' } eurobis_occurrences <- function(type, url = NULL, mrgid = NULL, geometry = NULL, dasid = NULL, - startdate = NULL, enddate = NULL, - aphiaid = NULL, scientificname = NULL, + start_date = NULL, end_date = NULL, + aphiaid = NULL, scientific_name = NULL, functional_groups = NULL, cites = NULL, habitats_directive = NULL, @@ -75,16 +75,16 @@ eurobis_occurrences <- function(type, if(!is.null(url)){ viewparams <- extract_viewparams(url) }else if(is.null(url)){ - viewparams <- build_viewparams(mrgid, geometry, dasid, startdate, enddate, aphiaid, + viewparams <- build_viewparams(mrgid, geometry, dasid, start_date, end_date, aphiaid, functional_groups, cites, habitats_directive, iucn_red_list, msdf_indicators) } # Handle Scientific name - if(!is.null(aphiaid) & !is.null(scientificname)){ - warning("Both aphiaid and scientificname provided: Ignoring scientificname") - }else if(!is.null(scientificname)){ - aphiaid <- eurobis_name2id(scientificname) + if(!is.null(aphiaid) & !is.null(scientific_name)){ + warning("Both aphiaid and scientific_name provided: Ignoring scientific_name") + }else if(!is.null(scientific_name)){ + aphiaid <- eurobis_name2id(scientific_name) } # WFS diff --git a/R/viewparams.R b/R/viewparams.R index 8c3aa4d..6d4ca27 100644 --- a/R/viewparams.R +++ b/R/viewparams.R @@ -13,12 +13,12 @@ build_encode <- function(query){ # build_viewparams(polygon = 'POLYGON((-2 52,-2 58,9 58,9 52,-2 52))') # build_viewparams(mrgid = 8364, polygon = 'POLYGON((-2 52,-2 58,9 58,9 52,-2 52))') # build_viewparams(dasid = 216) -# build_viewparams(dasid = 216, startdate = "2000-01-01", enddate = "2022-01-31") +# build_viewparams(dasid = 216, start_date = "2000-01-01", end_date = "2022-01-31") # build_viewparams(mrgid = 8364, polygon = 'POLYGON((-2 52,-2 58,9 58,9 52,-2 52))', -# dasid = 216, startdate = "2000-01-01", enddate = "2022-01-31", +# dasid = 216, start_date = "2000-01-01", end_date = "2022-01-31", # aphiaid = c(104108, 148947)) build_viewparams <- function(mrgid = NULL, geometry = NULL, dasid = NULL, - startdate = NULL, enddate = NULL, aphiaid = NULL, + start_date = NULL, end_date = NULL, aphiaid = NULL, functional_groups = NULL, cites = NULL, habitats_directive = NULL, iucn_red_list = NULL, msdf_indicators = NULL ){ @@ -26,7 +26,7 @@ build_viewparams <- function(mrgid = NULL, geometry = NULL, dasid = NULL, filters <- c( build_filter_geo(mrgid, geometry), build_filter_dataset(dasid), - build_filter_time(startdate, enddate), + build_filter_time(start_date, end_date), build_filter_traits(functional_groups, cites, habitats_directive, iucn_red_list, msdf_indicators) ) @@ -173,17 +173,17 @@ build_filter_geo <- function(mrgid = NULL, polygon = NULL){ # build_filter_time(as.Date("2000-01-01"), "2022-01-31") # build_filter_time(NULL, "2022-01-31") # build_filter_time("2000-01-01", NULL) -build_filter_time <- function(startdate = NULL, enddate = NULL){ +build_filter_time <- function(start_date = NULL, end_date = NULL){ - dates <- list(startdate, enddate) + dates <- list(start_date, end_date) dates_are_null <- unlist(lapply(dates, is.null)) if(all(dates_are_null)) return(NULL) - if(any(dates_are_null)) stop("Both startdate and enddate must be provided or ignored") + if(any(dates_are_null)) stop("Both start_date and end_date must be provided or ignored") dates_as_date <- lapply(dates, as.Date) - if(dates_as_date[[1]] > dates_as_date[[2]]) stop("startdate cannot be smaller than enddate") + if(dates_as_date[[1]] > dates_as_date[[2]]) stop("start_date cannot be smaller than end_date") dates_as_char <- lapply(dates_as_date, as.character) diff --git a/README.md b/README.md index a39738a..bbeea4f 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ occ <- eurobis_occurrences("basic", dasid = 8045) ``` ```r -occ2 <- eurobis_occurrences("basic", dasid = 8045, scientificname = "Zostera marina") +occ2 <- eurobis_occurrences("basic", dasid = 8045, scientific_name = "Zostera marina") ``` ```r diff --git a/man/eurobis_occurrences.Rd b/man/eurobis_occurrences.Rd index e57188c..40ef39e 100644 --- a/man/eurobis_occurrences.Rd +++ b/man/eurobis_occurrences.Rd @@ -13,10 +13,10 @@ eurobis_occurrences( mrgid = NULL, geometry = NULL, dasid = NULL, - startdate = NULL, - enddate = NULL, + start_date = NULL, + end_date = NULL, aphiaid = NULL, - scientificname = NULL, + scientific_name = NULL, functional_groups = NULL, cites = NULL, habitats_directive = NULL, @@ -53,13 +53,13 @@ with \code{\link{eurobis_map_draw}}} \item{dasid}{IMIS dataset unique identifier. See list of available datasets with \code{\link{eurobis_list_datasets}}} -\item{startdate}{Start date of occurrences. Format YYYY-MM-DD.} +\item{start_date}{Start date of occurrences. Format YYYY-MM-DD.} -\item{enddate}{End date of occurrences. Format YYYY-MM-DD.} +\item{end_date}{End date of occurrences. Format YYYY-MM-DD.} \item{aphiaid}{WoRMS taxon unique identifier. See \url{https://www.marinespecies.org/} and \url{https://docs.ropensci.org/worrms/}} -\item{scientificname}{Taxon name. It is matched with WoRMS on the fly. Ignored if aphiaid is provided.} +\item{scientific_name}{Taxon name. It is matched with WoRMS on the fly. Ignored if aphiaid is provided.} \item{functional_groups}{Functional groups available in WoRMS: See \code{eurobis::species_traits}.} @@ -100,7 +100,7 @@ test <- eurobis_occurrences_full_and_paremeters(dasid = 8045) # Get occurrences from Zostera marina in the ecoregion Alboran Sea (MRGID 21897) # See also ?eurobis_list_regions -test <- eurobis_occurrences_full(mrgid = 21897, scientificname = "Zostera marina") +test <- eurobis_occurrences_full(mrgid = 21897, scientific_name = "Zostera marina") # Get zooplankton occurrences from the region of your choice # See ?eurobis_map_mr and ?eurobis::species_traits @@ -108,6 +108,6 @@ my_area <- eurobis_map_draw() test <- eurobis_occurrences_basic(geometry = my_area, functional_groups = "zooplankton") # Get occurrences from the Continuous Plankton Recorder (dataset id 216) in January 2016 -test <- eurobis_occurrences_basic(dasid = 216, startdate = "2016-01-01", enddate = "2016-01-31") +test <- eurobis_occurrences_basic(dasid = 216, start_date = "2016-01-01", end_date = "2016-01-31") } } diff --git a/tests/testthat/test-viewparams.R b/tests/testthat/test-viewparams.R index addf59e..b4b981d 100644 --- a/tests/testthat/test-viewparams.R +++ b/tests/testthat/test-viewparams.R @@ -78,7 +78,7 @@ test_that("viewParams are build correctly", { # All together is_character <- is.character( build_viewparams(mrgid = 8364, geometry = wkt, - dasid = 216, startdate = "2000-01-01", enddate = "2022-01-31", + dasid = 216, start_date = "2000-01-01", end_date = "2022-01-31", aphiaid = c(104108, 148947), functional_groups = c("algae", "zooplankton"), cites = "I", diff --git a/tests/testthat/test-wfsrequest.R b/tests/testthat/test-wfsrequest.R index aa295ad..cf0432a 100644 --- a/tests/testthat/test-wfsrequest.R +++ b/tests/testthat/test-wfsrequest.R @@ -14,10 +14,10 @@ test_that("eurobis_occurrences", { expect_true(is_sf_df) } - #' test <- eurobis_occurrences("basic", dasid = 8045, scientificname = "Zostera marina") - #' test <- eurobis_occurrences("basic", dasid = 8045, scientificname = c("Zostera marina", "foo")) - #' test <- eurobis_occurrences("basic", dasid = 8045, scientificname = "foo") - #' test <- eurobis_occurrences("basic", dasid = 8045, scientificname = "Zostera marina", aphiaid = 145795) + #' test <- eurobis_occurrences("basic", dasid = 8045, scientific_name = "Zostera marina") + #' test <- eurobis_occurrences("basic", dasid = 8045, scientific_name = c("Zostera marina", "foo")) + #' test <- eurobis_occurrences("basic", dasid = 8045, scientific_name = "foo") + #' test <- eurobis_occurrences("basic", dasid = 8045, scientific_name = "Zostera marina", aphiaid = 145795) }) @@ -33,8 +33,8 @@ test_that("sf handler works fine", { test_ok <- eurobis_occurrences( "basic", geometry = pol_gibraltar, - startdate = "1990-01-01", - enddate = "1995-12-31", + start_date = "1990-01-01", + end_date = "1995-12-31", functional_groups = "mammals" ) expect_true(methods::is(test_ok, "sf")) @@ -44,8 +44,8 @@ test_that("sf handler works fine", { eurobis_occurrences( "basic", geometry = pol_gibraltar, - startdate = "1990-01-01", - enddate = "1995-12-31", + start_date = "1990-01-01", + end_date = "1995-12-31", functional_groups = "pisces" ) )