From c36401fe200a19838d11e112715622a450e40bbd Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Wed, 8 Nov 2023 14:24:11 +0100 Subject: [PATCH] add writeArgs to calcOutput --- R/calcOutput.R | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/R/calcOutput.R b/R/calcOutput.R index dcb9fe8b..a128eec4 100644 --- a/R/calcOutput.R +++ b/R/calcOutput.R @@ -29,6 +29,7 @@ #' always interpreted as TRUE. #' @param regionmapping alternative regionmapping to use for the given calculation. It will temporarily #' overwrite the global setting just for this calculation. +#' @param writeArgs a list of additional, named arguments to be supplied to write.report #' @param ... Additional settings directly forwarded to the corresponding #' calculation function #' @return magpie object with the requested output data either on country or on @@ -101,7 +102,8 @@ calcOutput <- function(type, aggregate = TRUE, file = NULL, years = NULL, # nolint round = NULL, signif = NULL, supplementary = FALSE, - append = FALSE, warnNA = TRUE, na_warning = NULL, try = FALSE, regionmapping = NULL, ...) { # nolint + append = FALSE, warnNA = TRUE, na_warning = NULL, try = FALSE, # nolint + regionmapping = NULL, writeArgs = NULL, ...) { argumentValues <- c(as.list(environment()), list(...)) # capture arguments for logging setWrapperActive("calcOutput") @@ -402,11 +404,18 @@ calcOutput <- function(type, aggregate = TRUE, file = NULL, years = NULL, # noli vcat(0, "The parameter append=TRUE works only when the file name is provided in the calcOutput() function call.") } + if (is.null(file) && !is.null(writeArgs)) { + vcat(0, "The parameter writeArgs works only when the file name is provided in the calcOutput() function call.") + } + if (!is.null(file)) { if (x$class == "magpie") { if (grepl(".mif", file) == TRUE) { if (!is.null(getYears(x$x))) { - write.report(x$x, file = paste(getConfig("outputfolder"), file, sep = "/"), unit = x$unit, append = append) + do.call(write.report, c( + list(x$x, file = file.path(getConfig("outputfolder"), file), unit = x$unit, append = append), + writeArgs + )) } else { vcat(0, "Time dimension missing and data cannot be written to a mif-file. Skip data set!") }