diff --git a/R/readEDGETransport.R b/R/readEDGETransport.R index 1c748934..cea505a6 100644 --- a/R/readEDGETransport.R +++ b/R/readEDGETransport.R @@ -12,7 +12,7 @@ #' \dontrun{ a <- readSource(type="EDGETransport") #' } #' @importFrom magclass read.magpie -#' @importFrom data.table rbindlist fread setcolorder := setnames setkey +#' @importFrom data.table rbindlist fread setcolorder := setnames setkeyv #' @importFrom rmndt approx_dt #' @@ -51,26 +51,27 @@ readEDGETransport <- function(subtype = "logit_exponent") { } create_copy_demscens <- function(dt) { - setkey(dt, "DEM_scenario") + setkeyv(dt, c("DEM_scenario", "GDP_scenario", "EDGE_scenario")) ## Workaround for NAVIGATE: copy-create demand scenarios which we do not supply by EDGE-T dt <- rbind(dt, - dt["gdp_SSP2EU", nomatch=NULL][, DEM_scenario := "gdp_SSP2EU_NAV_ele"], - dt["gdp_SSP2EU", nomatch=NULL][, DEM_scenario := "gdp_SSP2EU_NAV_tec"], - dt["gdp_SSP2EU_lowdem", nomatch=NULL][, DEM_scenario := "gdp_SSP2EU_NAV_act"], - dt["gdp_SSP2EU_lowdem", nomatch=NULL][, DEM_scenario := "gdp_SSP2EU_NAV_all"], - dt["gdp_SSP2EU_lowdem", nomatch=NULL][, DEM_scenario := "gdp_SSP2_lowEn"] + dt[.("gdp_SSP2EU", "gdp_SSP2EU", "NAV_ele"), nomatch=NULL][ + , DEM_scenario := "gdp_SSP2EU_NAV_ele"], + dt[.("gdp_SSP2EU", "gdp_SSP2EU", "NAV_tec"), nomatch=NULL][ + , DEM_scenario := "gdp_SSP2EU_NAV_tec"], + dt[.("gdp_SSP2EU_lowdem", "gdp_SSP2EU", "NAV_act"), nomatch=NULL][ + , DEM_scenario := "gdp_SSP2EU_NAV_act"], + dt[.("gdp_SSP2EU_lowdem", "gdp_SSP2EU", "NAV_all"), nomatch=NULL][ + , DEM_scenario := "gdp_SSP2EU_NAV_all"] ) - setkey(dt, "DEM_scenario") + setkeyv(dt, "DEM_scenario") + dt[.("gdp_SSP2EU_lowdem"), DEM_scenario := "gdp_SSP2_lowEn"] scens <- unique(dt$DEM_scenario) - - ## this scenario is not supported by REMIND - dt <- dt[scens["gdp_SSP2EU_lowdem" != scens]] return(dt) } compress_magpie <- function(dt, ...) { dt <- create_copy_demscens(dt) - setkey(dt, "EDGE_scenario", "DEM_scenario", "GDP_scenario") + setkeyv(dt, c("EDGE_scenario", "DEM_scenario", "GDP_scenario")) mdata <- NULL for (i in unique(dt$EDGE_scenario)) { for (j in unique(dt$DEM_scenario)) {