Skip to content

Commit

Permalink
change to arguments to snake_case. Fix #17
Browse files Browse the repository at this point in the history
  • Loading branch information
salvafern committed May 10, 2022
1 parent 4053472 commit 3b11bcf
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
24 changes: 12 additions & 12 deletions R/eurobis_occurrences.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -46,23 +46,23 @@
#'
#' # 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
#' 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")
#' }
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,
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions R/viewparams.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ 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
){

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)
)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions man/eurobis_occurrences.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-viewparams.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-wfsrequest.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

})

Expand All @@ -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"))
Expand All @@ -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"
)
)
Expand Down

0 comments on commit 3b11bcf

Please sign in to comment.