From a292d9adf69a1edd7a7782f6fadabdfcfc12f7d4 Mon Sep 17 00:00:00 2001 From: CJ Yetman Date: Wed, 17 Apr 2024 17:58:26 +0200 Subject: [PATCH] deal with the malformed CSV text from `IEA-EV-dataEVsalesCarsProjection-APS.csv` --- R/prepare_weo_2022_scenario.R | 19 ++++++++++++++++--- man/prepare_weo_2022_scenario.Rd | 6 +++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/R/prepare_weo_2022_scenario.R b/R/prepare_weo_2022_scenario.R index fa7ba54..cd48597 100644 --- a/R/prepare_weo_2022_scenario.R +++ b/R/prepare_weo_2022_scenario.R @@ -12,8 +12,9 @@ #' `WEO2022_NZE_SteelData.csv`. #' @param weo_2022_sales_aps_auto_raw A data frame containing a raw import of #' `SalesAPS_rawdata.csv`. -#' @param weo_2022_electric_sales_aps_auto_raw A data frame containing a raw -#' import of `IEA-EV-dataEV salesCarsProjection-APS.csv`. +#' @param weo_2022_electric_sales_aps_auto_raw_text A vector of character +#' strings containing each line of a raw import of `IEA-EV-dataEV +#' salesCarsProjection-APS.csv`. #' #' @return A prepared WEO 2022 scenario data-frame. #' @@ -27,7 +28,19 @@ prepare_weo_2022_scenario <- function(weo_2022_ext_data_regions_raw, weo_2022_nze_auto_raw, weo_2022_nze_steel_raw, weo_2022_sales_aps_auto_raw, - weo_2022_electric_sales_aps_auto_raw) { + weo_2022_electric_sales_aps_auto_raw_text) { + lines_to_fix <- 3:length(weo_2022_electric_sales_aps_auto_raw_text) + weo_2022_electric_sales_aps_auto_raw_text[lines_to_fix] <- + paste0( + weo_2022_electric_sales_aps_auto_raw_text[lines_to_fix], + ",https://www.iea.org/reports/global-ev-outlook-2022/executive-summary" + ) + weo_2022_electric_sales_aps_auto_raw <- + readr::read_csv( + file = I(weo_2022_electric_sales_aps_auto_raw_text), + show_col_types = FALSE + ) + fossil_fuel <- weo_2022_fossil_fuels_raw %>% dplyr::filter(.data[["Variable"]] == "Supply") diff --git a/man/prepare_weo_2022_scenario.Rd b/man/prepare_weo_2022_scenario.Rd index f7cc855..ecb7e7c 100644 --- a/man/prepare_weo_2022_scenario.Rd +++ b/man/prepare_weo_2022_scenario.Rd @@ -11,7 +11,7 @@ prepare_weo_2022_scenario( weo_2022_nze_auto_raw, weo_2022_nze_steel_raw, weo_2022_sales_aps_auto_raw, - weo_2022_electric_sales_aps_auto_raw + weo_2022_electric_sales_aps_auto_raw_text ) } \arguments{ @@ -33,8 +33,8 @@ prepare_weo_2022_scenario( \item{weo_2022_sales_aps_auto_raw}{A data frame containing a raw import of \code{SalesAPS_rawdata.csv}.} -\item{weo_2022_electric_sales_aps_auto_raw}{A data frame containing a raw -import of \verb{IEA-EV-dataEV salesCarsProjection-APS.csv}.} +\item{weo_2022_electric_sales_aps_auto_raw_text}{A vector of character +strings containing each line of a raw import of \verb{IEA-EV-dataEV salesCarsProjection-APS.csv}.} } \value{ A prepared WEO 2022 scenario data-frame.