Skip to content

Commit

Permalink
avoid id prefix before handling NAs
Browse files Browse the repository at this point in the history
  • Loading branch information
cboettig committed Jan 9, 2019
1 parent 393ea01 commit fad5d5f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions data-raw/gbif.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ gbif_taxa <- taxon %>%
original_id = originalNameUsageID) %>%
rename(species = specificEpithet,
epithet = infraspecificEpithet) %>%
mutate(id = paste0("GBIF:", id),
species = paste(genus, species, epithet),
accepted_id = paste0("GBIF:", accepted_id),
original_id = paste0("GBIF:", original_id))
mutate(species = paste(genus, species, epithet))

## canonicalName appears to be: Genus + specificEpithet + infraspecificEpithet
## i.e. SpecificEpithet ~ a name at the "species" rank
Expand All @@ -30,7 +27,8 @@ gbif_wide <- gbif_taxa %>%
filter(taxonomicStatus == "accepted") %>%
select(id,
kingdom, phylum, class, order, family, genus, species, epithet,
genericName)
genericName) %>%
mutate(id = paste0("GBIF:", id))
write_tsv(gbif_wide, "data/gbif_hierarchy.tsv.bz2")
rm(gbif_wide)

Expand All @@ -46,7 +44,10 @@ gbif_taxa <-
accepted <- filter(gbif_taxa, name_type == "accepted") %>% mutate(accepted_id = id)
rest <- filter(gbif_taxa, name_type != "accepted") %>% filter(!is.na(accepted_id))

gbif_taxonid <- bind_rows(accepted, rest) %>%de_duplicate()
gbif_taxonid <- bind_rows(accepted, rest) %>%
de_duplicate() %>%
mutate(id = paste0("GBIF:", id),
accepted_id = paste0("GBIF:", accepted_id))
write_tsv(gbif_taxonid, "data/gbif_taxonid.tsv.bz2")


Expand All @@ -59,7 +60,9 @@ gbif_synonyms <- full_join(
gbif_taxonid %>%
filter(name_type == "accepted") %>%
select(-id)) %>%
select(name, synonym, synonym_id, accepted_id, rank, name_type)
select(name, synonym, synonym_id, accepted_id, rank, name_type) %>%
mutate(synonym_id = paste0("GBIF:", id),
accepted_id = paste0("GBIF:", accepted_id))

write_tsv(gbif_synonyms, "data/gbif_synonyms.tsv.bz2")

Expand Down

0 comments on commit fad5d5f

Please sign in to comment.