From 84f10266104a2b13019f1736944b6cbb1c5638b9 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 6 Jan 2025 13:37:40 +0100 Subject: [PATCH 1/2] read_watersurfaces(): use tidyselect expressions in across() (no .data) --- R/read_habitatdata.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/R/read_habitatdata.R b/R/read_habitatdata.R index a2efaa4..38bb219 100644 --- a/R/read_habitatdata.R +++ b/R/read_habitatdata.R @@ -640,7 +640,7 @@ read_watersurfaces <- mutate( across(where(is.character), ~ return(`Encoding<-`(.x, "UTF-8"))), - across(c(.data$Code), + across("Code", as.factor) ) %>% rename( @@ -746,12 +746,12 @@ read_watersurfaces <- replacement = ">="), across( c( - .data$area_name, - .data$depth_class, - .data$connectivity, - .data$usage, + "area_name", + "depth_class", + "connectivity", + "usage", matches("^water_level_management$") - ), + ), as.factor), wfd_type = .data$wfd_type %>% factor( @@ -809,7 +809,7 @@ read_watersurfaces <- mutate( across(where(is.character), ~ return(`Encoding<-`(.x, "UTF-8"))), - across(c(.data$Code), as.factor) + across("Code", as.factor) ) %>% rename( connectivity = "Code", From 19827a2b77125e25a16b93014b5ab33b4ec3a873 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 6 Jan 2025 13:40:17 +0100 Subject: [PATCH 2/2] read_watersurfaces(): replace matches("^...$") with any_of("...") --- NAMESPACE | 1 + R/read_habitatdata.R | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index fabfc5f..80083f7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -109,6 +109,7 @@ importFrom(stringr,str_to_title) importFrom(tidyr,nest) importFrom(tidyr,tribble) importFrom(tidyr,unnest) +importFrom(tidyselect,any_of) importFrom(tidyselect,where) importFrom(utils,packageDescription) importFrom(utils,packageVersion) diff --git a/R/read_habitatdata.R b/R/read_habitatdata.R index 38bb219..69085b4 100644 --- a/R/read_habitatdata.R +++ b/R/read_habitatdata.R @@ -582,6 +582,7 @@ read_watersurfaces_hab <- #' str_replace #' @importFrom tidyselect #' where +#' any_of #' @export read_watersurfaces <- function(file = NULL, @@ -728,16 +729,16 @@ read_watersurfaces <- select( polygon_id = "WVLC", wfd_code = "WTRLICHC", - matches("^hyla_code$"), + any_of("hyla_code"), name = "NAAM", area_name = "GEBIED", wfd_type = "KRWTYPE", - matches("^wfd_type_alternative$"), + any_of("wfd_type_alternative"), wfd_type_certain = "KRWTYPES", depth_class = "DIEPKL", connectivity = "CONNECT", usage = "FUNCTIE", - matches("^water_level_management$") + any_of("water_level_management") ) %>% mutate( depth_class = str_replace( @@ -750,7 +751,7 @@ read_watersurfaces <- "depth_class", "connectivity", "usage", - matches("^water_level_management$") + any_of("water_level_management") ), as.factor), wfd_type = .data$wfd_type %>% @@ -759,13 +760,13 @@ read_watersurfaces <- levels(wfd_typetransl$wfd_type) ), across( - matches("^wfd_type_alternative$"), + any_of("wfd_type_alternative"), ~ factor(., levels = levels(wfd_type_alttransl$wfd_type_alternative) )), across( - matches("^hyla_code$"), + any_of("hyla_code"), ~ ifelse(.data$hyla_code == 0, NA, .data$hyla_code)) @@ -879,13 +880,13 @@ read_watersurfaces <- select( "polygon_id", "wfd_code", - matches("^hyla_code$"), + any_of("hyla_code"), "name", "area_name", "wfd_type", "wfd_type_name", - matches("^wfd_type_alternative$"), - matches("^wfd_type_alt_name$"), + any_of("wfd_type_alternative"), + any_of("wfd_type_alt_name"), "wfd_type_certain", "depth_class", "connectivity",