### Information ### This script is used to convert the original guilds data to a userfriendly file. ### The input is the Gilden_Info (converted form Excel to a CSV) ### The output is the Gilden_Data, where every species is listed only once per guild. ### The output must be read in to Excel manually to correctly display ä,ö or ü. ### This script accompanies the 2026 report and dataset produced by the Translational Centre # biodiversity conservation, German title: "Ein Datensatz und Toolkit zur Verbesserung der Lebensraumvernetzung" ### Script developed by Johanna Gnägi and Sarah Richman. # Load packages library(dplyr) library(stringr) library(readr) # Help function for summarising text elements clean_collapse <- function(x) { x %>% na.omit() %>% .[. != ""] %>% unique() %>% str_squish() %>% paste(collapse = " ; ")} # Load data. Add file path and file name between quotation marks gilden_orig <- read_csv( "", col_types = cols( seed_mass = col_double())) # Process Data gilden_data <- gilden_orig %>% # source in one field mutate(source = str_c(data_year, data_country, data_source, sep = " | ")) %>% # group and summarize group_by(main_guilde, species, tax_id, tax_group) %>% summarise( species_syn = first(species_syn), species_de = first(species_de), add_guilds = first(add_guilds), # mean of numeric variables across( c(dd_low, hr_low, height, seed_mass, seed_size), ~ if (all(is.na(.))) NA else mean(., na.rm = TRUE), .names = "{.col}" ), # summarize text with help function dd_info = clean_collapse(dd_info), hr_info = clean_collapse(hr_info), disp_type = clean_collapse(disp_type), density = clean_collapse(density), barriers = clean_collapse(barriers), source = clean_collapse(source), .groups = "drop") %>% # Keep only species with some information filter( if_any( .cols = c(dd_low,hr_low,), ~ !is.na(.) & . != "")) # Export. Fill parenthesis with desired file path and file name write_csv()