From d2aebea11052cc3c85f6fb4ddafbd01ebfcecca8 Mon Sep 17 00:00:00 2001 From: antaldaniel Date: Thu, 28 Dec 2023 10:38:16 +0100 Subject: [PATCH] handle change from dependency eurostat and tidyverse --- R/employment_get.R | 25 ++++++++++++++++++------- R/iotable_get.R | 24 ++++++++++++------------ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/R/employment_get.R b/R/employment_get.R index 3703dae..1fe4f9a 100644 --- a/R/employment_get.R +++ b/R/employment_get.R @@ -56,6 +56,8 @@ employment_get <- function ( geo, stop("Labelling must be any of 'iotables', 'prod_na' [product x product] or 'induse' [industry x industry]") } + year_number <- as.numeric(year) + ## Avoiding no visible binding for global variable 'data' ---------- getdata <- function(...) { @@ -145,31 +147,40 @@ employment_get <- function ( geo, ## Geo selection and exception handling-------------------------------- if ( geo %in% unique (emp$geo) ) { - emp <- emp %>% dplyr::filter ( geo == geo ) + select_geo <- which(as.character(emp$geo) %in% as.character(geo)) + emp <- emp[select_geo, ] } else { stop ("No employment data found with geo parameter = ", geo ) } + if ( "TIME_PERIOD" %in% names(emp) ) { + # Breaking change from eurostat 4.0.0 + emp <- emp %>% rename ( time = TIME_PERIOD) + } + emp$year <- as.numeric(substr(as.character(emp$time), start = 1, stop = 4)) ## Year selection and exception handling ------------------------------------- - if ( year %in% unique ( emp$year ) ) { - emp <- emp %>% filter ( year == year ) + if ( year %in% unique (emp$year) ) { + select_year <- which(emp$year %in% year_number) + emp <- emp[select_year, ] } else { stop ("No employment data found with the year parameter = ", year ) } ## Age group selection and exception handling --------------------------------- if ( age %in% unique (emp$age) ) { - emp <- emp %>% filter (.data$age == age) + select_age <- which(as.character(emp$age) %in% as.character(age)) + emp <- emp[select_age, ] } else { stop ("No employment data found with the age parameter = ", age ) } ## Sex variable selection and exception handling-------------------------------- if ( sex %in% unique (emp$sex) ) { - emp <- emp %>% filter (.data$sex == sex) + select_sex <- which(as.character(emp$sex) %in% as.character(sex)) + emp <- emp[select_sex, ] } else { stop ("No employment data found with sex parameter = ", sex ) } @@ -181,13 +192,13 @@ employment_get <- function ( geo, employment <- emp %>% mutate ( nace_r2 = as.character(.data$nace_r2) ) %>% group_by ( nace_r2, year ) %>% - summarize ( values = mean(.data$values)) %>% + summarize ( values = mean(.data$values), .groups = "drop") %>% dplyr::rename ( emp_code = nace_r2 ) %>% ungroup () %>% left_join ( employment_metadata, by = "emp_code") %>% # iotables:::employment_metadata dplyr::group_by ( code, variable, iotables_label ) %>% - dplyr::summarize ( values = sum(.data$values)) + dplyr::summarize ( values = sum(.data$values), .groups = "drop") ## If data_directory exists, save results ------------------------------- diff --git a/R/iotable_get.R b/R/iotable_get.R index d90ba19..3666868 100644 --- a/R/iotable_get.R +++ b/R/iotable_get.R @@ -188,17 +188,17 @@ iotable_get <- function ( labelled_io_data = NULL, metadata_uk_2010 <- getdata(metadata_uk_2010) metadata_cols <- metadata_uk_2010 %>% - dplyr::filter ( !is.na(.data$uk_col)) %>% + dplyr::filter ( !is.na(uk_col)) %>% dplyr::select ( -uk_row, -uk_row_label, -prod_na, -row_order) %>% - mutate ( uk_col = gsub("\\.", "-", as.character(.data$uk_col))) %>% - mutate ( uk_col = gsub(" & ", "-", as.character(.data$uk_col))) %>% - mutate ( uk_col = trimws(.data$uk_col, 'both')) + mutate ( uk_col = gsub("\\.", "-", as.character(uk_col))) %>% + mutate ( uk_col = gsub(" & ", "-", as.character(uk_col))) %>% + mutate ( uk_col = trimws(uk_col, 'both')) metadata_rows <- metadata_uk_2010 %>% - filter ( !is.na(.data$uk_row)) %>% + filter ( !is.na(uk_row)) %>% select ( -all_of(c("uk_col", "uk_col_label", "induse", "col_order")) ) %>% - mutate ( uk_row = gsub("\\.", "-", as.character(.data$uk_row))) %>% - mutate ( uk_row = gsub(" & ", "-", as.character(.data$uk_row))) + mutate ( uk_row = gsub("\\.", "-", as.character(uk_row))) %>% + mutate ( uk_row = gsub(" & ", "-", as.character(uk_row))) prod_ind <- c(prod_ind, uk_tables) } else { @@ -240,19 +240,19 @@ iotable_get <- function ( labelled_io_data = NULL, croatia_2010_1700 <- getdata(croatia_2010_1700) labelled_io_data <- croatia_2010_1700 %>% - mutate ( year = lubridate::year(.data$time)) + mutate ( year = lubridate::year(time)) } else if ( source_inputed == "croatia_2010_1800" ) { croatia_2010_1800 <- getdata(croatia_2010_1800) labelled_io_data <- croatia_2010_1800 %>% - mutate ( year = lubridate::year (.data$time)) + mutate ( year = lubridate::year (time)) } else if ( source_inputed == "croatia_2010_1900" ) { croatia_2010_1900 <- getdata(croatia_2010_1900) labelled_io_data <- croatia_2010_1900 %>% - mutate ( year = lubridate::year(.data$time)) + mutate ( year = lubridate::year(time)) } else { if ( tmp_rds %in% list.files (path = tempdir()) ) { @@ -430,8 +430,8 @@ iotable_get <- function ( labelled_io_data = NULL, } else if ( labelling == "short" & source %in% prod_ind ) { iotable_labelled_w <- iotable_labelled %>% - dplyr::select (.data$prod_na, induse, values) %>% - dplyr::filter ( !is.na(.data$prod_na) ) %>% + dplyr::select (prod_na, induse, values) %>% + dplyr::filter ( !is.na(prod_na) ) %>% tidyr::spread (induse, values ) } else {