Skip to content

Commit

Permalink
handle change from dependency eurostat and tidyverse
Browse files Browse the repository at this point in the history
  • Loading branch information
antaldaniel committed Dec 28, 2023
1 parent 3780cc3 commit d2aebea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
25 changes: 18 additions & 7 deletions R/employment_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)
{
Expand Down Expand Up @@ -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 )
}
Expand All @@ -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 -------------------------------
Expand Down
24 changes: 12 additions & 12 deletions R/iotable_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()) ) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d2aebea

Please sign in to comment.