Skip to content

Instantly share code, notes, and snippets.

@damianooldoni
Last active March 20, 2023 13:01
Show Gist options
  • Save damianooldoni/e70aded982934ca22ecdab62e20a9f0e to your computer and use it in GitHub Desktop.
Save damianooldoni/e70aded982934ca22ecdab62e20a9f0e to your computer and use it in GitHub Desktop.
How to read an occurrence.txt GBIF download and do a basic analysis at species level (n occs, min/max eventDate). Data used in example have been retrieved via https://gist.github.com/damianooldoni/b16608eef989aa17a296adcaa71537e5. GBIF download: https://www.gbif.org/occurrence/download/0104018-230224095556074
library(readr)
library(dplyr)
library(purrr)
# specify your path
occs <- read_tsv("../../0104018-230224095556074_eu_ias_occs.txt",
guess_max = 100000,
na = ""
)
occs_info_summary <- occs %>%
group_by(speciesKey) %>%
summarise(nObs = n(),
sumIndividualCount = sum(individualCount),
firstObs = min(eventDate, na.rm = TRUE),
lastObs = max(eventDate, na.rm = TRUE)) %>%
left_join(occs %>%
distinct(species, speciesKey),
join_by(speciesKey)) %>%
# add scientific name of the species as it could be that all occurrences come from subtaxa
mutate(scientificName = map_chr(.data$speciesKey,
function(x) {
name_usage(x)$data %>%
pull(scientificName)
})) %>%
rename(gbifTaxonKey = speciesKey) %>%
select(gbifTaxonKey, scientificName,
nObs, sumIndividualCount,
firstObs, lastObs) %>%
arrange(scientificName)
# save as csv file
occs_info_summary %>% write_csv(file = "eu_ias_info_from_gbif.csv", na = "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment