Skip to content

Commit

Permalink
fixing gbif to have more data
Browse files Browse the repository at this point in the history
  • Loading branch information
bomeara committed Jun 15, 2019
1 parent a387b50 commit 43d81e4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
11 changes: 6 additions & 5 deletions R/dataFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ library(plyr)
#'
#' @param query name of the clade of interest
#' @param rank the clade's rank (e.g. "genus")
#' @param gbif_limit Maximum number of records to return (hard limit is 200000)
#' @return A data frame (tibble) of key, scientific name, decimal latitude, and decimal longitude
#' @export



gbif_taxon_query <- function (query, rank){
gbif_taxon_query <- function (query, rank=NULL, gbif_limit=200000){
key <- rgbif::name_suggest(q=query, rank=rank)$key[1]
dat <- rgbif::occ_search(taxonKey=key, fields="minimal", limit=300)

dat <- rgbif::occ_search(taxonKey=key, fields="minimal", limit=gbif_limit)
return(dat)
}

Expand All @@ -24,13 +24,14 @@ gbif_taxon_query <- function (query, rank){
#' Query gbif to return latitude and longitude for a vector of species
#'
#' @param species a vector of species names
#' @param gbif_limit Maximum number of records to return (hard limit is 200000)
#' @return A data frame (tibble) of key, scientific name, decimal latitude, and decimal longitude
#' @export

gbif_species_query <- function (species){
gbif_species_query <- function (species, gbif_limit=200000){
all.records <- data.frame()
for (species_index in seq_along(species)) {
all.records <- plyr::rbind.fill(all.records, rgbif::occ_search(scientificName = species[species_index], fields="minimal", limit = 300)$data)
all.records <- plyr::rbind.fill(all.records, rgbif::occ_search(scientificName = species[species_index], fields="minimal", limit = gbif_limit)$data)
}
return(all.records)
}
Expand Down
4 changes: 3 additions & 1 deletion man/gbif_species_query.Rd

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

4 changes: 3 additions & 1 deletion man/gbif_taxon_query.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-match_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ test_that("chapter2_fitGeiger works", {
fc_result <- chapter2_fitGeiger(chapter2, keep="continuous")
expect_true(inherits(fc_result[[1]][[1]], "gfit"))
})

test_that("gbif_taxon_query works", {
result <- gbif_taxon_query("Puma", gbif_limit=600)
expect_true(inherits(result$data$decimalLatitude), "numeric")
})

0 comments on commit 43d81e4

Please sign in to comment.