knitr::opts_chunk$set(echo = FALSE)
library(dplyr)
library(LSVI)
library(rmarkdown)
library(knitr)
if (
  inherits(params$ConnectieLSVIhabitats, "DBIConnection") |
    inherits(params$ConnectieLSVIhabitats, "Pool")
) {
  ConnectieLSVIhabitats <- params$ConnectieLSVIhabitats
} else {
  ConnectieLSVIhabitats <- connecteerMetLSVIdb()
}

Indicatoren <-
  selecteerIndicatoren(
    ConnectieLSVIhabitats = ConnectieLSVIhabitats,
    Versie = params$Versie,
    Habitatgroep = params$Habitatgroep,
    Habitattype = params$Habitattype,
    HabitatnamenToevoegen = TRUE
  ) %>%
  select(
    "Versie", "Habitatgroepnaam", "Habitattype", "Habitatnaam",
    "Habitatsubtype", "Habitatsubtypenaam"
  ) %>%
  distinct()
Uitvoer <- NULL

for (VersieRapportdeel in unique(Indicatoren$Versie)) { #nolint
  Uitvoer <- c(Uitvoer, paste("#", VersieRapportdeel, sep = " "))
  VersieIndicatoren <- Indicatoren %>%
    filter(.data$Versie == VersieRapportdeel) %>%
    arrange(.data$Habitattype)
  for (Habitatgroep in unique(VersieIndicatoren$Habitatgroepnaam)) {
    Uitvoer <- c(Uitvoer, paste("##", Habitatgroep, sep = " "))
    Subset <- VersieIndicatoren %>%
      filter(.data$Habitatgroepnaam == Habitatgroep)
    for (Habitat in unique(as.character(Subset$Habitattype))) {
      Subsubset <- Subset %>%
        filter(.data$Habitattype == Habitat)
      Habitatnaam <-
        ifelse(
          is.na(unique(Subsubset$Habitatnaam)),
          "",
          paste(": ", unique(Subsubset$Habitatnaam), sep = "")
        )
      Uitvoer <-
        c(
          Uitvoer,
          paste("### Habitattype ", Habitat, Habitatnaam, "\n", sep = "")
        )
      for (HabitatsubtypeFiche in
           unique(as.character(Subsubset$Habitatsubtype))) {
        Habitatsubtypenaam <-
          ifelse(
            is.na(
              unique(
                (Subsubset %>%
                   filter(.data$Habitatsubtype == HabitatsubtypeFiche)
                 )$Habitatsubtypenaam)
              ),
            "",
            paste(
              ": ",
              unique(
                (Subsubset %>%
                   filter(.data$Habitatsubtype == HabitatsubtypeFiche)
                 )$Habitatsubtypenaam
                ),
              sep = ""
            )
          )
        if (HabitatsubtypeFiche != Habitat) {
          Uitvoer <-
            c(Uitvoer,
              paste("#### Habitatsubtype ", HabitatsubtypeFiche,
                    Habitatsubtypenaam, "\n", sep = ""))
        }
        Uitvoer <-
          c(Uitvoer,
            knit_child("Habitatfiche.Rmd"))
      }
    }
  }
}
cat(Uitvoer, sep = "\n")


inbo/LSVI documentation built on Sept. 9, 2023, 10:38 a.m.