Skip to content

Commit

Permalink
add writeArgs to calcOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Nov 8, 2023
1 parent b65b40c commit c36401f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions R/calcOutput.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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!")
}
Expand Down

0 comments on commit c36401f

Please sign in to comment.