diff --git a/CHANGELOG.md b/CHANGELOG.md index f043ba224..852c8f116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### changed - **21_trade** refactor equations for enhanced readablility and improve documentation +- **script** rewrite of merge_report.R based on rds files and rbind, which allows for more flexibility when merging reports. Avoid inconsistent use of "GLO" instead of "World" in report.rds files. ### added - **scripts** added output report `EU_report.R` that uses `EU_report.Rmd` diff --git a/scripts/output/merge_report.R b/scripts/output/merge_report.R index aa4856e78..18dbe5b58 100644 --- a/scripts/output/merge_report.R +++ b/scripts/output/merge_report.R @@ -30,27 +30,24 @@ if(!exists("source_include")) { cat("\nStarting output generation\n") missing <- NULL +out <- NULL -if(file.exists("output/report_all.mif")) file.rename("output/report_all.mif","output/report_all.bak") +if(file.exists("output/report_all.rds")) file.rename("output/report_all.rds","output/report_all_bak.rds") +if(file.exists("output/report_all.mif")) file.rename("output/report_all.mif","output/report_all_bak.mif") for (i in 1:length(outputdir)) { print(paste("Processing",outputdir[i])) - #gdx file - rep<-file.path(outputdir[i],"report.mif") + rep<-file.path(outputdir[i],"report.rds") if(file.exists(rep)) { - #get scenario name - cfg <- gms::loadConfig(file.path(outputdir[i], "config.yml")) - scen <- cfg$title - #read-in reporting file - a <- read.report(rep,as.list = FALSE) - getNames(a,dim=1) <- scen - #add to reporting mif file - write.report(a,file="output/report_all.mif",append=TRUE,ndigit = 4,skipempty = FALSE) + a <- readRDS(rep) + out <- rbind(out,a) } else missing <- c(missing,outputdir[i]) } + +saveRDS(out,file="output/report_all.rds") +write.mif(out,"output/report_all.mif") + if (!is.null(missing)) { cat("\nList of folders with missing report.mif\n") print(missing) } - -if(file.exists("output/report_all.mif")) saveRDS(read.quitte("output/report_all.mif"),file = "output/report_all.rds") diff --git a/scripts/output/rds_report.R b/scripts/output/rds_report.R index e02197b0b..6bec3dbaa 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -48,8 +48,13 @@ for (mapping in c("AR6", "NAVIGATE", "SHAPE", "AR6_MAgPIE")) { } write.report(report, file = mif) + q <- as.quitte(report) +# as.quitte converts "World" into "GLO". But we want to keep "World" and therefore undo these changes q <- droplevels(q) +levels(q$region)[levels(q$region) == "GLO"] <- "World" +q$region <- factor(q$region,levels = sort(levels(q$region))) + if(all(is.na(q$value))) stop("No values in reporting!") saveRDS(q, file = rds, version = 2) diff --git a/scripts/output/rds_report_iso.R b/scripts/output/rds_report_iso.R index c21958831..52cf2aa57 100644 --- a/scripts/output/rds_report_iso.R +++ b/scripts/output/rds_report_iso.R @@ -31,7 +31,13 @@ rds_iso <- paste0(outputdir, "/report_iso.rds") ############################################################################### report <- getReportIso(gdx, scenario = cfg$title, dir = outputdir) + q <- as.quitte(report) +# as.quitte converts "World" into "GLO". But we want to keep "World" and therefore undo these changes +q <- droplevels(q) +levels(q$region)[levels(q$region) == "GLO"] <- "World" +q$region <- factor(q$region,levels = sort(levels(q$region))) + if (all(is.na(q$value))) { stop("No values in reporting!") }