Skip to content

Commit

Permalink
fixed broken test in dataset_metrics, made them better, tidied datase…
Browse files Browse the repository at this point in the history
…t_metrics fxn
  • Loading branch information
sckott committed Mar 17, 2015
1 parent e230aa3 commit ebbae57
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
13 changes: 8 additions & 5 deletions R/dataset_metrics.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#'
#' @param uuid (character) One or more dataset UUIDs. See examples.
#' @param ... Further named parameters, such as \code{query}, \code{path}, etc, passed on to
#' \code{\link[httr]{modify_url}} within \code{\link[httr]{GET}} call. Unnamed parameters will
#' be combined with \code{\link[httr]{config}}.
#' \code{\link[httr]{modify_url}} within \code{\link[httr]{GET}} call. Unnamed parameters will
#' be combined with \code{\link[httr]{config}}.
#'
#' @references \url{http://www.gbif.org/developer/registry#datasetMetrics}
#'
Expand All @@ -19,11 +19,14 @@
#' dataset_metrics(uuid='66dd0960-2d7d-46ee-a491-87b9adcfe7b1', config=verbose())
#' }

dataset_metrics <- function(uuid, ...)
{
dataset_metrics <- function(uuid, ...) {
getdata <- function(x){
url <- sprintf('%s/dataset/%s/metrics', gbif_base(), x)
gbif_GET(url, list(), FALSE, ...)
}
if(length(uuid)==1) getdata(uuid) else lapply(uuid, getdata)
if(length(uuid) == 1) {
getdata(uuid)
} else {
lapply(uuid, getdata)
}
}
4 changes: 2 additions & 2 deletions man/dataset_metrics.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ dataset_metrics(uuid, ...)
\item{uuid}{(character) One or more dataset UUIDs. See examples.}

\item{...}{Further named parameters, such as \code{query}, \code{path}, etc, passed on to
\code{\link[httr]{modify_url}} within \code{\link[httr]{GET}} call. Unnamed parameters will
be combined with \code{\link[httr]{config}}.}
\code{\link[httr]{modify_url}} within \code{\link[httr]{GET}} call. Unnamed parameters will
be combined with \code{\link[httr]{config}}.}
}
\description{
Get details on a GBIF dataset.
Expand Down
17 changes: 12 additions & 5 deletions tests/testthat/test-dataset_metrics.r
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
context("dataset_metrics")

tt <- dataset_metrics(uuid='3f8a1297-3259-4700-91fc-acc4170b27ce')
tt <- dataset_metrics('3f8a1297-3259-4700-91fc-acc4170b27ce')
ss <- dataset_metrics(uuid=c('3f8a1297-3259-4700-91fc-acc4170b27ce',
'66dd0960-2d7d-46ee-a491-87b9adcfe7b1'))

test_that("returns the correct class", {
test_that("dataset_metrics returns the correct class", {
expect_is(tt, "list")
expect_is(tt$key, "integer")
expect_is(tt$datasetKey, "character")

expect_is(ss, "list")
expect_is(ss[[1]]$key, "integer")
expect_is(ss[[2]]$datasetKey, "character")
})

test_that("returns the correct value", {
expect_equal(tt$key, 4341)
expect_equal(tt$datasetKey, "3f8a1297-3259-4700-91fc-acc4170b27ce")
test_that("dataset_metrics fails well", {
expect_error(dataset_metrics(), "argument \"uuid\" is missing")
expect_error(dataset_metrics(""))
expect_error(dataset_metrics(c('3f8a1297-3259-4700-91fc-acc4170b27ce', 4)))
})

0 comments on commit ebbae57

Please sign in to comment.