tests/testthat/test-tabGBIF.R

context("GBIF tabulation")

library(occCite)

test_that("data entered into tabGBIF is as expected", {
  skip_on_cran() # Requires GBIF login information

  GBIFLogin <- try(GBIFLoginManager(), silent = T)
  skip_if(is(GBIFLogin, "try-error"), "GBIF login unsuccessful")

  key <- 5637947
  occD <- prevGBIFdownload(key, GBIFLogin)
  res <- rgbif::occ_download_get(
    key = occD, overwrite = TRUE,
    file.path(system.file("extdata/",
      package = "occCite"
    ))
  )

  expect_equal(class(res), "occ_download_get")
})

test_that("verify occ_download_import results have expected columns", {
  skip_on_cran() # Requires GBIF login information

  GBIFLogin <- try(GBIFLoginManager(), silent = T)
  skip_if(is(GBIFLogin, "try-error"), "GBIF login unsuccessful")

  key <- 5637947
  occD <- prevGBIFdownload(key, GBIFLogin)
  res <- rgbif::occ_download_get(
    key = occD, overwrite = TRUE,
    file.path(system.file("extdata/",
      package = "occCite"
    ))
  )
  occFromGBIF <- rgbif::occ_download_import(res)

  expect_true("data.frame" %in% class(occFromGBIF))
  expect_true("species" %in% colnames(occFromGBIF))
  expect_true("decimalLongitude" %in% colnames(occFromGBIF))
  expect_true("decimalLatitude" %in% colnames(occFromGBIF))
  expect_true("day" %in% colnames(occFromGBIF))
  expect_true("month" %in% colnames(occFromGBIF))
  expect_true("year" %in% colnames(occFromGBIF))
  expect_true("datasetName" %in% colnames(occFromGBIF))
  expect_true("datasetKey" %in% colnames(occFromGBIF))
})

test_that("tabGBIF results as expected", {
  skip_on_cran() # Requires GBIF login information

  GBIFLogin <- try(GBIFLoginManager(), silent = T)
  skip_if(is(GBIFLogin, "try-error"), "GBIF login unsuccessful")

  key <- 5637947
  occD <- prevGBIFdownload(key, GBIFLogin)
  res <- rgbif::occ_download_get(
    key = occD, overwrite = TRUE,
    file.path(system.file("extdata/", package = "occCite"))
  )
  occFromGBIF <- occCite:::tabGBIF(GBIFresults = res, "Protea cynaroides")

  expect_equal(class(occFromGBIF), "data.frame")
  expect_true("name" %in% colnames(occFromGBIF))
  expect_true("longitude" %in% colnames(occFromGBIF))
  expect_true("latitude" %in% colnames(occFromGBIF))
  expect_true("day" %in% colnames(occFromGBIF))
  expect_true("month" %in% colnames(occFromGBIF))
  expect_true("year" %in% colnames(occFromGBIF))
  expect_true("Dataset" %in% colnames(occFromGBIF))
  expect_true("DatasetKey" %in% colnames(occFromGBIF))
  expect_true("DataService" %in% colnames(occFromGBIF))
})

Try the occCite package in your browser

Any scripts or data that you put into this service are public.

occCite documentation built on Aug. 5, 2022, 5:09 p.m.