diff --git a/Demographics/1. Demographics - Population.R b/Demographics/1. Demographics - Population.R index bab18361..301cb7d6 100755 --- a/Demographics/1. Demographics - Population.R +++ b/Demographics/1. Demographics - Population.R @@ -501,7 +501,7 @@ HSCP <- as.character(filter(lookup, hscp_locality == LOCALITY)$hscp2019name) # Determine other localities based on LOCALITY object other_locs <- lookup %>% select(hscp_locality, hscp2019name) %>% - filter(hscp2019name == HSCP & hscp_locality != LOCALITY) %>% + filter(hscp2019name == HSCP, hscp_locality != LOCALITY) %>% arrange(hscp_locality) # Find number of locs per partnership diff --git a/Demographics/2. Demographics - SIMD.R b/Demographics/2. Demographics - SIMD.R index 85aad905..69e82a8d 100644 --- a/Demographics/2. Demographics - SIMD.R +++ b/Demographics/2. Demographics - SIMD.R @@ -474,7 +474,7 @@ HSCP <- as.character(filter(lookup, hscp_locality == LOCALITY)$hscp2019name) # Determine other localities based on LOCALITY object other_locs <- lookup %>% select(hscp_locality, hscp2019name) %>% - filter(hscp2019name == HSCP & hscp_locality != LOCALITY) %>% + filter(hscp2019name == HSCP, hscp_locality != LOCALITY) %>% arrange(hscp_locality) # Find number of locs per partnership diff --git a/Households/Households Code.R b/Households/Households Code.R index 4dd2aa7e..420b23dc 100755 --- a/Households/Households Code.R +++ b/Households/Households Code.R @@ -293,7 +293,7 @@ HSCP <- as.character(filter(lookup2, hscp_locality == LOCALITY)$hscp2019name) # Determine other localities based on LOCALITY object other_locs <- lookup2 %>% select(hscp_locality, hscp2019name) %>% - filter(hscp2019name == HSCP & hscp_locality != LOCALITY) %>% + filter(hscp2019name == HSCP, hscp_locality != LOCALITY) %>% arrange(hscp_locality) # Find number of locs per partnership diff --git a/Lifestyle & Risk Factors/2. Lifestyle & Risk Factors Outputs.R b/Lifestyle & Risk Factors/2. Lifestyle & Risk Factors Outputs.R index 0182e0c1..90235ea5 100755 --- a/Lifestyle & Risk Factors/2. Lifestyle & Risk Factors Outputs.R +++ b/Lifestyle & Risk Factors/2. Lifestyle & Risk Factors Outputs.R @@ -41,7 +41,7 @@ HB <- as.character(filter(lookup, hscp_locality == LOCALITY)$hb2019name) # Determine other localities based on LOCALITY object other_locs <- lookup %>% select(hscp_locality, hscp2019name) %>% - filter(hscp2019name == HSCP & hscp_locality != LOCALITY) %>% + filter(hscp2019name == HSCP, hscp_locality != LOCALITY) %>% arrange(hscp_locality) # Find number of locs per partnership @@ -229,15 +229,15 @@ alcohol_hosp_bar alcohol_hosp_latest <- filter( alcohol_hosp, - year == max(alcohol_hosp$year) & - (area_name == LOCALITY & area_type == "Locality") -)$measure + year == max(alcohol_hosp[["year"]]), + (area_name == LOCALITY & area_type == "Locality") +)[["measure"]] alcohol_hosp_earliest <- filter( alcohol_hosp, - (year == min(alcohol_hosp$year)) & - (area_name == LOCALITY & area_type == "Locality") -)$measure + (year == min(alcohol_hosp[["year"]])), + (area_name == LOCALITY & area_type == "Locality") +)[["measure"]] alcohol_hosp_change <- abs( (alcohol_hosp_latest - alcohol_hosp_earliest) / alcohol_hosp_earliest * 100 @@ -250,8 +250,9 @@ alcohol_hosp_change_word <- if_else( scot_alcohol_hosp <- filter( alcohol_hosp, - year == max(alcohol_hosp$year) & area_name == "Scotland" -)$measure + year == max(alcohol_hosp[["year"]]), + area_name == "Scotland" +)[["measure"]] alcohol_hosp_diff_scot <- if_else( alcohol_hosp_latest > scot_alcohol_hosp, @@ -300,14 +301,14 @@ alcohol_deaths_bar alcohol_deaths_latest <- filter( alcohol_deaths, - year == max(alcohol_deaths$year) & - (area_name == LOCALITY & area_type == "Locality") + year == max(alcohol_deaths$year), + (area_name == LOCALITY & area_type == "Locality") )$measure alcohol_deaths_earliest <- filter( alcohol_deaths, - (year == min(alcohol_deaths$year)) & - (area_name == LOCALITY & area_type == "Locality") + (year == min(alcohol_deaths$year)), + (area_name == LOCALITY & area_type == "Locality") )$measure alcohol_deaths_change <- abs( @@ -323,7 +324,8 @@ alcohol_deaths_change_word <- if_else( scot_alcohol_deaths <- filter( alcohol_deaths, - year == max(alcohol_deaths$year) & area_name == "Scotland" + year == max(alcohol_deaths$year), + area_name == "Scotland" )$measure alcohol_deaths_diff_scot <- if_else( @@ -373,14 +375,14 @@ bowel_screening_bar bowel_screening_latest <- filter( bowel_screening, - year == max(bowel_screening$year) & - (area_name == LOCALITY & area_type == "Locality") + year == max(bowel_screening$year), + (area_name == LOCALITY & area_type == "Locality") )$measure bowel_screening_earliest <- filter( bowel_screening, - (year == min(bowel_screening$year)) & - (area_name == LOCALITY & area_type == "Locality") + (year == min(bowel_screening$year)), + (area_name == LOCALITY & area_type == "Locality") )$measure bowel_screening_change <- abs( @@ -397,7 +399,8 @@ bowel_screening_change_word <- if_else( scot_bowel_screening <- filter( bowel_screening, - year == max(bowel_screening$year) & area_name == "Scotland" + year == max(bowel_screening$year), + area_name == "Scotland" )$measure bowel_screening_diff_scot <- if_else( @@ -453,8 +456,8 @@ other_locs_bowel_screening <- other_locs_summary_table( hscp_drug_hosp <- round_half_up( filter( drug_hosp, - year == max(year) & - (area_name == HSCP & area_type == "HSCP") + year == max(year), + (area_name == HSCP & area_type == "HSCP") )$measure, 1 ) @@ -462,8 +465,8 @@ hscp_drug_hosp <- round_half_up( hscp_alcohol_hosp <- round_half_up( filter( alcohol_hosp, - year == max(year) & - (area_name == HSCP & area_type == "HSCP") + year == max(year), + (area_name == HSCP & area_type == "HSCP") )$measure, 1 ) @@ -471,8 +474,8 @@ hscp_alcohol_hosp <- round_half_up( hscp_alcohol_deaths <- round_half_up( filter( alcohol_deaths, - year == max(year) & - (area_name == HSCP & area_type == "HSCP") + year == max(year), + (area_name == HSCP & area_type == "HSCP") )$measure, 1 ) @@ -480,8 +483,8 @@ hscp_alcohol_deaths <- round_half_up( hscp_bowel_screening <- round_half_up( filter( bowel_screening, - year == max(year) & - (area_name == HSCP & area_type == "HSCP") + year == max(year), + (area_name == HSCP & area_type == "HSCP") )$measure, 1 ) diff --git a/Master RMarkdown Document & Render Code/Global Script.R b/Master RMarkdown Document & Render Code/Global Script.R index 0e210b8d..cb5ff512 100755 --- a/Master RMarkdown Document & Render Code/Global Script.R +++ b/Master RMarkdown Document & Render Code/Global Script.R @@ -314,7 +314,7 @@ read_in_pop_proj <- memoise(read_in_pop_proj_raw) clean_scotpho_dat <- function(data) { data |> - filter(area_type != "Council area" & area_type != "Intermediate zone") |> + filter(area_type != "Council area", area_type != "Intermediate zone") |> mutate(area_name = gsub("&", "and", area_name, fixed = TRUE)) |> mutate( area_name = if_else( diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 558dba5f..dbbeba71 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -45,7 +45,7 @@ HB <- as.character(filter(localities, hscp_locality == LOCALITY)$hb2019name) # Determine other localities based on LOCALITY object other_locs <- localities %>% select(hscp_locality, hscp2019name) %>% - filter(hscp2019name == HSCP & hscp_locality != LOCALITY) %>% + filter(hscp2019name == HSCP, hscp_locality != LOCALITY) %>% arrange(hscp_locality) # Find number of locs per partnership @@ -624,7 +624,8 @@ max_year_ubd <- max(bed_days_areas$financial_year) first_fy_rate_ubd <- filter( bed_days_areas, financial_year == min(financial_year), - location == LOCALITY & area_type == "Locality" + location == LOCALITY, + area_type == "Locality" )$data latest_bed_days_loc <- bed_days_areas %>% @@ -638,7 +639,8 @@ word_change_ubd <- word_change_calc(latest_bed_days_loc2, first_fy_rate_ubd) # HSCP first_fy_hscp_ubd <- filter( bed_days_areas, - (financial_year == min(bed_days_areas$financial_year)) & (area_type == "HSCP") + (financial_year == min(bed_days_areas$financial_year)), + (area_type == "HSCP") )$data hscp_bed_days <- bed_days_areas %>% @@ -654,8 +656,8 @@ hscp_change_ubd <- word_change_calc(hscp_bed_days2, first_fy_hscp_ubd) # Scotland first_fy_scot_ubd <- filter( bed_days_areas, - (financial_year == min(bed_days_areas$financial_year)) & - (area_type == "Scotland") + (financial_year == min(bed_days_areas$financial_year)), + (area_type == "Scotland") )$data scot_bed_days <- bed_days_areas %>% @@ -1954,8 +1956,8 @@ psych_hosp_time_trend <- psych_hosp %>% psych_hosp_latest <- round_half_up( filter( psych_hosp, - year == max(psych_hosp$year) & - (area_name == LOCALITY & area_type == "Locality") + year == max(psych_hosp$year), + (area_name == LOCALITY & area_type == "Locality") )$measure, 1 ) @@ -1973,13 +1975,14 @@ other_locs_psych_hosp <- psych_hosp %>% hscp_psych_hosp <- round_half_up( filter( psych_hosp, - year == max(year) & (area_name == HSCP & area_type == "HSCP") + year == max(year), + (area_name == HSCP & area_type == "HSCP") )$measure, 1 ) scot_psych_hosp <- round_half_up( - filter(psych_hosp, year == max(year) & area_name == "Scotland")$measure, + filter(psych_hosp, year == max(year), area_name == "Scotland")$measure, 1 ) @@ -1992,8 +1995,8 @@ list_years_latest <- list_years$period loc_psych_hosp <- psych_hosp %>% filter(period %in% list_years_latest) %>% filter( - area_name == LOCALITY & - area_type == "Locality", + area_name == LOCALITY, + area_type == "Locality", year == min(year) | year == max(year) ) %>% mutate(measure2 = format(measure, big.mark = ",")) @@ -2011,8 +2014,8 @@ word_change_loc_psych <- word_change_calc( hscp_psych_hosp <- psych_hosp %>% filter(period %in% list_years_latest) %>% filter( - area_name == HSCP & - area_type == "HSCP", + area_name == HSCP, + area_type == "HSCP", year == min(year) | year == max(year) ) %>% mutate(measure2 = format(measure, big.mark = ",")) @@ -2030,8 +2033,8 @@ word_change_hscp_psych <- word_change_calc( hb_psych_hosp <- psych_hosp %>% filter(period %in% list_years_latest) %>% filter( - area_name == HB & - area_type == "Health board", + area_name == HB, + area_type == "Health board", year == min(year) | year == max(year) ) %>% mutate(measure2 = format(measure, big.mark = ",")) @@ -2049,8 +2052,8 @@ word_change_hb_psych <- word_change_calc( scot_psych_hosp <- psych_hosp %>% filter(period %in% list_years_latest) %>% filter( - area_name == "Scotland" & - area_type == "Scotland", + area_name == "Scotland", + area_type == "Scotland", year == min(year) | year == max(year) ) %>% mutate(measure2 = format(measure, big.mark = ","))