From 1051a720e082fa069f728f8def7a898cc4a7f796 Mon Sep 17 00:00:00 2001 From: John Waller Date: Thu, 4 Jan 2024 09:21:42 +0100 Subject: [PATCH] fixing tests --- NAMESPACE | 2 + R/dataset.R | 2 +- R/dataset_list_funs.R | 16 +++--- R/dataset_uuid_funs.R | 3 +- man/dataset.Rd | 65 +++++++++++++++++++------ man/dataset_list_funs.Rd | 34 +++++++++++++ tests/testthat/test-dataset_list_funs.R | 4 +- 7 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 man/dataset_list_funs.Rd diff --git a/NAMESPACE b/NAMESPACE index 8a35999d..6c50cb0e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,6 +31,7 @@ export(dataset_comment) export(dataset_constituents) export(dataset_contact) export(dataset_doi) +export(dataset_duplicate) export(dataset_endpoint) export(dataset_export) export(dataset_get) @@ -39,6 +40,7 @@ export(dataset_identifier) export(dataset_machinetag) export(dataset_metrics) export(dataset_networks) +export(dataset_noendpoint) export(dataset_process) export(dataset_search) export(dataset_suggest) diff --git a/R/dataset.R b/R/dataset.R index b7382363..8878a3e8 100644 --- a/R/dataset.R +++ b/R/dataset.R @@ -35,7 +35,7 @@ #' #' @export #' -#' @examples \dontrun { +#' @examples \dontrun{ #' dataset(limit=3) #' dataset(country="US",limit=3) #' dataset(type="CHECKLIST",limit=3) diff --git a/R/dataset_list_funs.R b/R/dataset_list_funs.R index 64ceb071..bc44bbc6 100644 --- a/R/dataset_list_funs.R +++ b/R/dataset_list_funs.R @@ -1,6 +1,5 @@ #' List datasets that are deleted or have no endpoint. #' -#' @name dataset_list_funs.R #' #' @param limit Controls the number of results in the page. #' @param start Determines the start for the search results. @@ -12,28 +11,27 @@ #' Get a list of deleted datasets or datasets with no endpoint. You get the full #' and no parameters aside from `limit` and `start` are accepted. #' -#' @export -#' -#' @examples \dontrun { #' +#' @examples \dontrun{ +#' dataset_noendpoint(limit=3) #' } -#' @name dataset_list_funs.R +#' @name dataset_list_funs #' @export dataset_duplicate <- function(limit=20,start=NULL,curlopts=list()) { - dataset_list_get_(endpoint="duplicate",limit=limit,start=start, + dataset_list_get_(endpoint="duplicate/",limit=limit,start=start, curlopts=curlopts,meta=TRUE) } -#' @name dataset_list_funs.R +#' @name dataset_list_funs #' @export dataset_noendpoint <- function(limit=20,start=NULL,curlopts=list()) { - dataset_list_get_(endpoint="withNoEndpoint",limit=limit,start=start, + dataset_list_get_(endpoint="withNoEndpoint/",limit=limit,start=start, curlopts=curlopts,meta=TRUE) } dataset_list_get_ <- function(endpoint,limit=NULL,start=NULL,curlopts,meta) { - url <- paste0(gbif_base(),"/dataset/",endpoint,"/") + url <- paste0(gbif_base(),"/dataset/",endpoint) if(!is.null(limit)) { args <- rgbif_compact(c(limit=limit,offset=start)) tt <- gbif_GET(url, args, TRUE, curlopts) diff --git a/R/dataset_uuid_funs.R b/R/dataset_uuid_funs.R index 36417659..ad60f9a2 100644 --- a/R/dataset_uuid_funs.R +++ b/R/dataset_uuid_funs.R @@ -1,6 +1,5 @@ #' Get dataset metadata using a datasetkey #' -#' @name dataset_uuid_funs #' @param uuid A GBIF datasetkey uuid. #' @param limit Number of records to return. #' @param start Record number to start at. @@ -96,7 +95,7 @@ dataset_tag <- function(uuid = NULL, curlopts = list()) { #' @name dataset_uuid_funs #' @export dataset_metrics <- function(uuid = NULL, curlopts = list()) { - if(!is_uuid(uuid)) warn("'uuid' should be a GBIF datasetkey uuid.") + if(!is_uuid(uuid)) stop("'uuid' should be a GBIF datasetkey uuid.") if(!dataset_get(uuid)$type == "CHECKLIST") stop("Dataset should be a checklist.") url <- paste0(gbif_base(),"/dataset/",uuid,"/metrics") res <- rgbif_compact(gbif_GET(url, args = NULL, TRUE, curlopts)) diff --git a/man/dataset.Rd b/man/dataset.Rd index e79332f1..e1310916 100644 --- a/man/dataset.Rd +++ b/man/dataset.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/dataset.R \name{dataset} \alias{dataset} -\title{Title} +\title{Search for more obscure dataset metadata.} \usage{ dataset( country = NULL, @@ -14,41 +14,74 @@ dataset( machineTagValue = NULL, modified = NULL, query = NULL, + deleted = FALSE, limit = NULL, start = NULL, curlopts = list() ) } \arguments{ -\item{country}{} +\item{country}{The 2-letter country code (as per ISO-3166-1) of the country +publishing the dataset.} -\item{type}{} +\item{type}{The primary type of the dataset. +Available values : OCCURRENCE, CHECKLIST, METADATA, SAMPLING_EVENT, +MATERIAL_ENTITY.} -\item{identifierType}{} +\item{identifierType}{An identifier type for the identifier parameter. +Available values : URL, LSID, HANDLER, DOI, UUID, FTP, URI, UNKNOWN, +GBIF_PORTAL, GBIF_NODE, GBIF_PARTICIPANT, GRSCICOLL_ID, GRSCICOLL_URI, +IH_IRN, ROR, GRID, CITES, SYMBIOTA_UUID, WIKIDATA, NCBI_BIOCOLLECTION.} -\item{identifier}{} +\item{identifier}{An identifier of the type given by the identifierType +parameter.} -\item{machineTagNamespace}{} +\item{machineTagNamespace}{Filters for entities with a machine tag in the +specified namespace.} -\item{machineTagName}{} +\item{machineTagName}{Filters for entities with a machine tag with the +specified name (use in combination with the machineTagNamespace parameter).} -\item{machineTagValue}{} +\item{machineTagValue}{Filters for entities with a machine tag with the +specified value (use in combination with the machineTagNamespace and machineTagName parameters).} -\item{modified}{} +\item{modified}{The modified date of the dataset. Accepts ranges and a '' +can be used as a wildcard, e.g.:modified=2023-04-01,} -\item{query}{} +\item{query}{Simple full text search parameter. The value for this parameter +can be a simple word or a phrase. Wildcards are not supported.} -\item{limit}{} +\item{deleted}{Logical specifying whether to return only deleted datasets.} -\item{start}{} +\item{limit}{Controls the number of results in the page.} -\item{curlopts}{} +\item{start}{Determines the start for the search results.} + +\item{curlopts}{options passed on to \link[crul:HttpClient]{crul::HttpClient}.} +} +\value{ +A \code{list}. } \description{ -Title +Search for more obscure dataset metadata. +} +\details{ +This function allows you to search for some more obscure dataset metadata +that might not be possible with \code{dataset_search()}. For example, searching +through registry machinetags. } \examples{ -\dontrun { - +\dontrun{ +dataset(limit=3) +dataset(country="US",limit=3) +dataset(type="CHECKLIST",limit=3) +dataset(identifierType = "URL",limit=3) +dataset(identifier = 168,limit=3) +dataset(machineTagNamespace = "metasync.gbif.org",limit=3) +dataset(machineTagName = "datasetTitle",limit=3) +dataset(machineTagValue = "Borkhart",limit=3) +dataset(modified = "2023-04-01", limit=3) +dataset(q = "dog", limit=3) +dataset(deleted=TRUE,limit=3) } } diff --git a/man/dataset_list_funs.Rd b/man/dataset_list_funs.Rd new file mode 100644 index 00000000..0d92407d --- /dev/null +++ b/man/dataset_list_funs.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dataset_list_funs.R +\name{dataset_list_funs} +\alias{dataset_list_funs} +\alias{dataset_duplicate} +\alias{dataset_noendpoint} +\title{List datasets that are deleted or have no endpoint.} +\usage{ +dataset_duplicate(limit = 20, start = NULL, curlopts = list()) + +dataset_noendpoint(limit = 20, start = NULL, curlopts = list()) +} +\arguments{ +\item{limit}{Controls the number of results in the page.} + +\item{start}{Determines the start for the search results.} + +\item{curlopts}{options passed on to \link[crul:HttpClient]{crul::HttpClient}.} +} +\value{ +A \code{list}. +} +\description{ +List datasets that are deleted or have no endpoint. +} +\details{ +Get a list of deleted datasets or datasets with no endpoint. You get the full +and no parameters aside from \code{limit} and \code{start} are accepted. +} +\examples{ +\dontrun{ +dataset_noendpoint(limit=3) +} +} diff --git a/tests/testthat/test-dataset_list_funs.R b/tests/testthat/test-dataset_list_funs.R index 4ffd1247..50a95364 100644 --- a/tests/testthat/test-dataset_list_funs.R +++ b/tests/testthat/test-dataset_list_funs.R @@ -6,9 +6,9 @@ test_that("dataset_list_funs work as expected.", { e <- dataset_noendpoint(limit=3) }) - expect_is(e,"tbl_df") + expect_is(e,"list") expect_named(e,c("meta","data")) expect_is(e$data$key,"character") - expect_lte(nrow(e), 3) + expect_lte(nrow(e$data), 3) })