traitecoevo / austraits.build

Source for AusTraits
Other
16 stars 2 forks source link

Sort taxonomic updates in alphabetical order #777

Closed dfalster closed 8 months ago

dfalster commented 8 months ago

@ehwenk suggested

  1. The taxonomic_updates section of metadata files should be sorted alphabetically
  2. New additions should be inserted alphabetically

this will make it easier to maintain and lead to fewer merge conflicts

library(tidyverse)
library(traits.build)

ids <- dir("data")
metadata <- map(ids, ~read_metadata(sprintf("data/%s/metadata.yml", .x)))

# function to update a single file
f <- function(m){
  if(!is.na(m$taxonomic_updates[1]))
    m$taxonomic_updates <- 
      m$taxonomic_updates %>% util_list_to_df2() %>% arrange(find) %>%
      mutate(taxonomic_resolution = tolower(taxonomic_resolution))
  m
}

# apply updates
metadata_updated <- map(metadata, f)

# save to file
walk2(metadata_updated, ids, ~ write_metadata(.x, sprintf("data/%s/metadata.yml", .y)))