Skip to content

Commit

Permalink
Merge pull request #246 from Loisel/fix/issue245
Browse files Browse the repository at this point in the history
Fix check for existing reporting file to append the EDGE-T reporting
  • Loading branch information
Loisel authored May 5, 2022
2 parents fea19fb + dd4c295 commit c97b30f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 17 additions & 9 deletions R/reportEDGETransport.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
#'
#' @param output_folder path to the output folder, default is current folder.
#' @param remind_root path to the REMIND root directory, defaults to two levels up from output_folder.
#' @param append try to find the REMIND output file in the output folder and append to it. If FALSE, the function returns a quitte object with the reporting variables.
#' @author Alois Dirnaichner Marianna Rottoli
#'
#' @importFrom rmndt approx_dt readMIF writeMIF
#' @importFrom gdxdt readgdx
#' @importFrom data.table fread fwrite rbindlist copy CJ
#' @importFrom dplyr %>%
#' @importFrom quitte as.quitte
#' @export

reportEDGETransport <- function(output_folder=".",
remind_root=NULL) {
remind_root=NULL,
append=TRUE) {

if(is.null(remind_root)){
remind_root <- file.path(output_folder, "../..")
Expand Down Expand Up @@ -67,12 +70,6 @@ reportEDGETransport <- function(output_folder=".",

demand_ej <- readRDS(datapath(fname = "demandF_plot_EJ.RDS")) ## detailed final energy demand, EJ

name_mif = list.files(output_folder, pattern = "REMIND_generic", full.names = F)
name_mif = file.path(output_folder, name_mif[!grepl("withoutPlu", name_mif)])

stopifnot(typeof(name_mif) == "character")
miffile <- readMIF(name_mif)

## ES and FE Demand

reportingESandFE <- function(datatable, mode){
Expand Down Expand Up @@ -659,6 +656,17 @@ reportEDGETransport <- function(output_folder=".",
toMIF <- data.table::dcast(toMIF, ... ~ period, value.var="value")
setnames(toMIF, colnames(toMIF)[1:5], c("Model", "Scenario", "Region", "Variable", "Unit"))

writeMIF(toMIF, name_mif, append=T)
deletePlus(name_mif, writemif=T)
if(append){
name_mif <- list.files(output_folder, pattern = "REMIND_generic", full.names = F) %>%
.[!grepl("withoutPlu|adjustedPolicy", .)]
stopifnot(!is.na(name_mif) && length(name_mif) == 1)

name_mif <- file.path(output_folder, name_mif)


writeMIF(toMIF, name_mif, append=T)
deletePlus(name_mif, writemif=T)
}else{
return(as.quitte(toMIF))
}
}
4 changes: 3 additions & 1 deletion man/reportEDGETransport.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c97b30f

Please sign in to comment.