Retrieving the current list of environmental pressures from the reference googlesheet and moving data to two n2khab data sources

Append extra names to namelist

Reading from the source googlesheet:

source_df <-
    ep_gs_id %>%
    read_sheet(sheet = sheet_names(ep_gs_id)[1])

Adding multilingual EP names and abbreviations to namelist:

source_df %>% 
    select(code = Environmental_pressure_code,
           nl_name = Environmental_pressure_name_NL,
           en_name = Environmental_pressure_name_EN,
           nl_shortname = Environmental_pressure_abbrev_NL,
           en_shortname = Environmental_pressure_abbrev_EN) %>% 
    gather(key = "key", 
           value = "value",
           matches(".+name|.+explanation|.+epclass")) %>% 
    separate(key, c("lang", "key")) %>% 
    spread(key = key,
           value = value) %>% 
    bind_rows(read_vc(namelist_path, root),
              .) %>% 
    write_vc(namelist_path, root)

Adding explanations to namelist:

source_df %>% 
    select(code = Environmental_pressure_code,
           nl_name = Explanation_NL,
           en_name = Explanation_EN,
           nl_shortname = Remarks_NL,
           en_shortname = Remarks_EN) %>% 
    mutate(code = str_c(code, "_explan")) %>% 
    gather(key = "key", 
           value = "value",
           contains("name")) %>% 
    separate(key, c("lang", "key")) %>% 
    spread(key = key,
           value = value) %>% 
    filter(!is.na(name) | !is.na(shortname)) %>% 
    bind_rows(read_vc(namelist_path, root),
              .) %>% 
    write_vc(namelist_path, root)

Adding ep_classes to namelist:

source_df %>% 
    select(code = Environmental_pressure_code,
           nl_name = Environmental_pressure_class_NL,
           en_name = Environmental_pressure_class_EN) %>% 
    gather(key = "key", 
           value = "value",
           contains("name")) %>% 
    separate(key, c("lang", "key")) %>% 
    spread(key = key,
           value = value) %>% 
    filter(!is.na(name)) %>% 
    mutate(code = str_c("ep_class_",
                        str_match(code, "ep_(..).*")[,2]
                        )
           ) %>% 
    mutate(shortname = NA %>% as.character) %>% 
    bind_rows(read_vc(namelist_path, root),
              .) %>% 
    write_vc(namelist_path, root)

Generate the env_pressures data source

Set path and filename of env_pressures:

ep_path <- "inst/textdata/env_pressures"

Generate:

source_df %>% 
    select(ep_code = Environmental_pressure_code) %>% 
    mutate(ep_class = str_c("ep_class_",
                        str_match(ep_code, "ep_(..).*")[,2]
                        ),
           explanation = str_c(ep_code, "_explan")
    ) %>% 
    mutate(ep_code = factor(ep_code),
           ep_class = factor(ep_class)) %>% 
    write_vc(ep_path,
             root,
             sorting = "ep_code",
             optimize = FALSE,
             strict = FALSE)


inbo/n2khab documentation built on Jan. 15, 2025, 9:36 a.m.