Skip to content

Instantly share code, notes, and snippets.

@PietrH
Created January 24, 2024 13:29
Show Gist options
  • Save PietrH/3d5e4c41d74bb1610f2051133bb1fda7 to your computer and use it in GitHub Desktop.
Save PietrH/3d5e4c41d74bb1610f2051133bb1fda7 to your computer and use it in GitHub Desktop.
Query gbif using rgbif::occ_data() but with multiple scientificNames at once
library(tidyverse)

# Example function of sending multiple scientificNames to rgbif::occ_data()
fetch_species_for_dimi <-
  function(scientificName = c("Vulpes vulpes", "Puma concolor"),
           country = "BE") {
    purrr::map(
      scientificName,
      ~ rgbif::occ_data(
        scientificName = .x,
        country = country,
        limit = 100000
      )$data
    ) %>%
      list_rbind()
  }

# Demo function
fetch_species_for_dimi()
#> # A tibble: 966 × 128
#>    key        scientificName  decimalLatitude decimalLongitude issues datasetKey
#>    <chr>      <chr>                     <dbl>            <dbl> <chr>  <chr>     
#>  1 4512254907 Vulpes vulpes …            50.8             4.43 cdc    50c9509d-…
#>  2 4018189241 Vulpes vulpes …            50.8             4.52 cdc,c… 50c9509d-…
#>  3 4022197800 Vulpes vulpes …            50.2             5.29 cdc,c… 50c9509d-…
#>  4 4441342189 Vulpes vulpes …            51.5             4.77 cdc,c… 8a5cbaec-…
#>  5 4441345688 Vulpes vulpes …            51.3             3.66 cdc,c… 8a5cbaec-…
#>  6 4063087300 Vulpes vulpes …            50.8             4.41 cdc,c… 50c9509d-…
#>  7 4111714982 Vulpes vulpes …            50.8             4.36 cdc,c… 50c9509d-…
#>  8 4080505750 Vulpes vulpes …            51.0             4.44 cdc,c… 50c9509d-…
#>  9 4080880532 Vulpes vulpes …            49.7             5.66 cdc,c… 50c9509d-…
#> 10 4091417639 Vulpes vulpes …            50.9             4.49 cdc,c… 50c9509d-…
#> # ℹ 956 more rows
#> # ℹ 122 more variables: publishingOrgKey <chr>, installationKey <chr>,
#> #   hostingOrganizationKey <chr>, publishingCountry <chr>, protocol <chr>,
#> #   lastCrawled <chr>, lastParsed <chr>, crawlId <int>, basisOfRecord <chr>,
#> #   occurrenceStatus <chr>, lifeStage <chr>, taxonKey <int>, kingdomKey <int>,
#> #   phylumKey <int>, classKey <int>, orderKey <int>, familyKey <int>,
#> #   genusKey <int>, speciesKey <int>, acceptedTaxonKey <int>, …

Created on 2024-01-24 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment