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.4.2 (2024-10-31 ucrt)
os Windows Server 2022 x64 (build 20348)
system x86_64, mingw32
ui RTerm
language en
collate English_United States.utf8
ctype English_United States.utf8
tz UTC
date 2024-12-23
pandoc 3.1.11 @ C:/HOSTED1/windows/pandoc/31F3871.11/x64/PANDOC~1.11/ (via rmarkdown)

Packages

#>  package     * version date (UTC) lib source
#>  bslib         0.8.0   2024-07-29 [1] CRAN (R 4.4.1)
#>  cachem        1.1.0   2024-05-16 [1] CRAN (R 4.4.0)
#>  cli           3.6.3   2024-06-21 [1] RSPM (R 4.4.0)
#>  desc          1.4.3   2023-12-10 [1] CRAN (R 4.4.0)
#>  digest        0.6.37  2024-08-19 [1] RSPM (R 4.4.0)
#>  dplyr       * 1.1.4   2023-11-17 [1] CRAN (R 4.4.0)
#>  evaluate      1.0.1   2024-10-10 [1] CRAN (R 4.4.1)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.4.0)
#>  fs            1.6.5   2024-10-30 [1] CRAN (R 4.4.1)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.4.0)
#>  glue          1.8.0   2024-09-30 [1] CRAN (R 4.4.1)
#>  htmltools     0.5.8.1 2024-04-04 [1] CRAN (R 4.4.0)
#>  htmlwidgets   1.6.4   2023-12-06 [1] CRAN (R 4.4.0)
#>  jquerylib     0.1.4   2021-04-26 [1] CRAN (R 4.4.0)
#>  jsonlite      1.8.9   2024-09-20 [1] RSPM (R 4.4.0)
#>  knitr         1.49    2024-11-08 [1] RSPM (R 4.4.0)
#>  kwb.utils     0.15.0  2024-04-25 [1] Github (kwb-r/kwb.utils@4415aa2)
#>  lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.4.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.4.0)
#>  pillar        1.10.0  2024-12-17 [1] CRAN (R 4.4.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.4.0)
#>  pkgdown       2.1.1   2024-09-17 [1] RSPM (R 4.4.0)
#>  purrr         1.0.2   2023-08-10 [1] CRAN (R 4.4.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.4.0)
#>  ragg          1.3.0   2024-03-13 [1] CRAN (R 4.4.0)
#>  rlang         1.1.4   2024-06-04 [1] CRAN (R 4.4.0)
#>  rmarkdown     2.29    2024-11-04 [1] CRAN (R 4.4.2)
#>  sass          0.4.9   2024-03-15 [1] CRAN (R 4.4.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.4.0)
#>  systemfonts   1.1.0   2024-05-15 [1] CRAN (R 4.4.0)
#>  textshaping   0.3.7   2023-10-09 [1] CRAN (R 4.4.0)
#>  tibble        3.2.1   2023-03-20 [1] CRAN (R 4.4.0)
#>  tidyr       * 1.3.1   2024-01-24 [1] CRAN (R 4.4.0)
#>  tidyselect    1.2.1   2024-03-11 [1] CRAN (R 4.4.0)
#>  vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.4.0)
#>  xfun          0.49    2024-10-31 [1] CRAN (R 4.4.1)
#>  yaml          2.3.10  2024-07-26 [1] RSPM (R 4.4.0)
#> 
#>  [1] D:/a/_temp/Library
#>  [2] C:/R/library

Pandoc

#>                                                pandoc_directory pandoc_version
#> 1 C:/HOSTED~1/windows/pandoc/31F387~1.11/x64/PANDOC~1.11/pandoc         3.1.11