Skip to contents

1 Install R packages

if (! require("remotes")) {
  install.packages("remotes", repos = "https://cloud.r-project.org")
}

remotes::install_github("kwb-r/kwb.geosalz", dependencies = TRUE)

2 Setup the project

2.1 Define paths

# Define paths and resolve placeholders
paths <- kwb.utils::resolve(list(
  servername = Sys.getenv("servername"),
  project = "geosalz", 
  processing_dir = "//<servername>/processing/<project>",
  ods_dir = "<processing_dir>/archiv/precleaned-data/emshoff91/converted_ods", 
  version = "0.9.0",
  export_xlsx_name = "emshoff91_v<version>.xlsx",
  export_xlsx_dir = "<processing_dir>/archiv/cleaned-data",
  export_xlsx_path = "<export_xlsx_dir>/<export_xlsx_name>"
))

#paths <- kwb.utils::resolve(paths, root = "C:/projects")

3 Data import

emshoff91_import <- kwb.geosalz::create_emshoff91_import(ods_dir = paths$ods_dir)

emshoff91_list <- kwb.geosalz::read_multiple_emshoff91_ods(emshoff91_import)

emshoff91_df <- kwb.geosalz::emshoff91_list_to_df(emshoff91_list)

emshoff91_df_remapped <- kwb.geosalz::emshoff91_remap_values(emshoff91_df)

emshoff91_df_remapped <- emshoff91_import %>%  
  dplyr::right_join(
    emshoff91_df_remapped,
    by = "ods_names_clean"
  ) %>% 
  dplyr::mutate(
    datum = as.Date(sprintf("19%s",.data$datum), format = "%Y/%m/%d"),
    rohr = stringr::str_replace(.data$rohr, "^0", "O"))

messstelle_split <- stringr::str_split_fixed(
  emshoff91_df_remapped$messstelle, 
  pattern = "\\s{1,9}",
  n = 3
) %>% 
  as.data.frame()

names(messstelle_split) <- c("objekt", "bhrgs_nr-jahr", "rohr")  

messstelle_split <- messstelle_split %>% 
  tibble::as_tibble() %>% 
  tidyr::separate(
    col = "bhrgs_nr-jahr", 
    into = c("bhrgs_nr", "jahr"),
    sep = "/",
    remove = FALSE
  ) %>% 
  dplyr::mutate(
    rohr = stringr::str_replace(.data$rohr, "^0", "O"), 
    ms = kwb.utils::multiSubstitute(
      messstelle_split$objekt,
      replacements = list(
        "GF|F-Gal." = "Gal_F",
        "GE|E-Gal" = "Gal_E",
        "GI|I-Gal." = "Gal_I",
        "GG|G-Gal.|G-Gal" = "Gal_G",
        "GK|K-Gal." = "Gal_K",
        "^Go$" = "Gal_O",
        "GH|H-Gal." = "Gal_H", 
        "GO" = "Gal_O",
        "GL|L-Gal." = "Gal_L", 
        "GM|M-Gal." = "Gal_M",
        ",," = ","
      )
    )
  ) 

messstelle_split2 <- messstelle_split$ms %>%
  stringr::str_split_fixed(pattern = ",", n = 2) %>%  
  as.data.frame()

names(messstelle_split2) <- c("brunnen_galerie", "brunnen_id")

messstelle_split2 <- messstelle_split2 %>% 
  dplyr::mutate(
    brunnen_id = stringr::str_remove(.data$brunnen_id, pattern = "^Br")
  )

ms_split <- dplyr::bind_cols(messstelle_split, messstelle_split2)

ms_split

samples_per_moni_id <- emshoff91_df_remapped %>%  
  dplyr::count(.data$messstelle) 

samples_per_moni_id_master <- emshoff91_df_remapped %>%  
  dplyr::count(
    .data$messstelle, 
    .data$rohr,
    .data$fi_mi, 
    .data$strat,
    .data$progr
  ) 

4 Export to Excel

openxlsx::write.xlsx(
  list(
    samples_per_moni_id = samples_per_moni_id, 
    samples_per_moni_id_master = samples_per_moni_id_master,
    data = emshoff91_df_remapped
  ),
  file = paths$export_xlsx_path,
  overwrite = TRUE
)

5 Session Info

Plattform

name value
version R version 4.2.3 (2023-03-15 ucrt)
os Windows Server x64 (build 20348)
system x86_64, mingw32
ui RTerm
language en
collate English_United States.utf8
ctype English_United States.utf8
tz UTC
date 2023-04-15
pandoc 2.19.2 @ C:/HOSTED1/windows/pandoc/2191.2/x64/PANDOC~1.2/ (via rmarkdown)

Packages

#>  package     * version date (UTC) lib source
#>  bslib         0.4.2   2022-12-16 [1] RSPM (R 4.2.0)
#>  cachem        1.0.7   2023-02-24 [1] RSPM (R 4.2.0)
#>  cli           3.6.1   2023-03-23 [1] RSPM (R 4.2.0)
#>  desc          1.4.2   2022-09-08 [1] RSPM (R 4.2.0)
#>  digest        0.6.31  2022-12-11 [1] RSPM (R 4.2.0)
#>  dplyr       * 1.1.1   2023-03-22 [1] RSPM (R 4.2.0)
#>  evaluate      0.20    2023-01-17 [1] RSPM (R 4.2.0)
#>  fansi         1.0.4   2023-01-22 [1] RSPM (R 4.2.0)
#>  fastmap       1.1.1   2023-02-24 [1] RSPM (R 4.2.0)
#>  fs            1.6.1   2023-02-06 [1] RSPM (R 4.2.0)
#>  generics      0.1.3   2022-07-05 [1] RSPM (R 4.2.0)
#>  glue          1.6.2   2022-02-24 [1] RSPM (R 4.2.0)
#>  htmltools     0.5.5   2023-03-23 [1] RSPM (R 4.2.0)
#>  jquerylib     0.1.4   2021-04-26 [1] RSPM (R 4.2.0)
#>  jsonlite      1.8.4   2022-12-06 [1] RSPM (R 4.2.0)
#>  knitr         1.42    2023-01-25 [1] RSPM (R 4.2.0)
#>  kwb.utils     0.14.0  2023-04-15 [1] Github (KWB-R/kwb.utils@56518c7)
#>  lifecycle     1.0.3   2022-10-07 [1] RSPM (R 4.2.0)
#>  magrittr      2.0.3   2022-03-30 [1] RSPM (R 4.2.0)
#>  memoise       2.0.1   2021-11-26 [1] RSPM (R 4.2.0)
#>  pillar        1.9.0   2023-03-22 [1] RSPM (R 4.2.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] RSPM (R 4.2.0)
#>  pkgdown       2.0.7   2022-12-14 [1] RSPM (R 4.2.0)
#>  purrr         1.0.1   2023-01-10 [1] RSPM (R 4.2.0)
#>  R6            2.5.1   2021-08-19 [1] RSPM (R 4.2.0)
#>  ragg          1.2.5   2023-01-12 [1] RSPM (R 4.2.0)
#>  rlang         1.1.0   2023-03-14 [1] RSPM (R 4.2.0)
#>  rmarkdown     2.21    2023-03-26 [1] RSPM (R 4.2.0)
#>  rprojroot     2.0.3   2022-04-02 [1] RSPM (R 4.2.0)
#>  sass          0.4.5   2023-01-24 [1] RSPM (R 4.2.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] RSPM (R 4.2.0)
#>  stringi       1.7.12  2023-01-11 [1] RSPM (R 4.2.0)
#>  stringr       1.5.0   2022-12-02 [1] RSPM (R 4.2.0)
#>  systemfonts   1.0.4   2022-02-11 [1] RSPM (R 4.2.0)
#>  textshaping   0.3.6   2021-10-13 [1] RSPM (R 4.2.0)
#>  tibble        3.2.1   2023-03-20 [1] RSPM (R 4.2.0)
#>  tidyr       * 1.3.0   2023-01-24 [1] RSPM (R 4.2.0)
#>  tidyselect    1.2.0   2022-10-10 [1] RSPM (R 4.2.0)
#>  utf8          1.2.3   2023-01-31 [1] RSPM (R 4.2.0)
#>  vctrs         0.6.1   2023-03-22 [1] RSPM (R 4.2.0)
#>  xfun          0.38    2023-03-24 [1] RSPM (R 4.2.0)
#>  yaml          2.3.7   2023-01-23 [1] RSPM (R 4.2.0)
#> 
#>  [1] D:/a/_temp/Library
#>  [2] C:/R/library

Pandoc

#>                                           pandoc_directory pandoc_version
#> 1 C:/HOSTED~1/windows/pandoc/219~1.2/x64/PANDOC~1.2/pandoc         2.19.2