diff --git a/R/CreateRunOptions.R b/R/CreateRunOptions.R index a7abda5d2a1bd45ed0e1c6f9d2437bfa9d5b044f..e6762391d008c9c850e558160ca951d6ca8f56c7 100644 --- a/R/CreateRunOptions.R +++ b/R/CreateRunOptions.R @@ -32,25 +32,24 @@ CreateRunOptions <- function(x, ...) { #' @rdname CreateRunOptions #' @export CreateRunOptions.InputsModel <- function(x, ...) { - hasFUN_MOD <- "FUN_MOD" %in% names(list(...)) - if (!hasFUN_MOD && !is.null(x$FUN_MOD)) { - CreateRunOptions(x, - FUN_MOD = x$FUN_MOD, - ...) - } else if (hasFUN_MOD){ - # Temporary fix waiting for resolution of HYCAR-Hydro/airgr#167 - if (identical(match.fun(x$FUN_MOD), RunModel_Lag)) { - dots <- list(...) - dots$InputsModel <- x - dots$IniStates <- CreateIniStates(RunModel_Lag, x) - do.call(airGR::CreateRunOptions, dots) + dots <- list(...) + dots$InputsModel <- x + + # Add FUN_MOD in parameters if carried by InputsModel + if (!"FUN_MOD" %in% names(dots)) { + if(!is.null(x$FUN_MOD)) { + dots$FUN_MOD <- x$FUN_MOD } else { - # End of temporary fix HYCAR-Hydro/airgr#167 - airGR::CreateRunOptions(InputsModel = x, ...) + stop(" The parameter `FUN_MOD` must be defined") } - } else { - stop(" The parameter `FUN_MOD` must be defined") } + + # Temporary fix waiting for resolution of HYCAR-Hydro/airgr#167 + if (identical(match.fun(dots$FUN_MOD), RunModel_Lag)) { + dots$IniStates <- CreateIniStates(RunModel_Lag, x) + } + # End of temporary fix HYCAR-Hydro/airgr#167 + do.call(airGR::CreateRunOptions, dots) } #' @rdname CreateRunOptions diff --git a/man/CreateRunOptions.Rd b/man/CreateRunOptions.Rd index b2765e8075bfaed8408b1a6941a7b60b585e4657..8e860ca9911cfc1f279bcab4fe120da7278660e4 100644 --- a/man/CreateRunOptions.Rd +++ b/man/CreateRunOptions.Rd @@ -15,9 +15,9 @@ CreateRunOptions(x, ...) \method{CreateRunOptions}{InputsModel}(x, ...) -\method{CreateRunOptions}{character}(x, ...) +\method{CreateRunOptions}{character}(x, InputsModel, ...) -\method{CreateRunOptions}{`function`}(x, ...) +\method{CreateRunOptions}{`function`}(x, InputsModel, ...) } \arguments{ \item{x}{For a single catchment, it can be an object of class \emph{InputsModel} or a \link{function} or a \link{character} corresponding to \code{FUN_MOD} (compliant with \strong{airGR} call). For a network, it should be an object of class \emph{GRiwrmInputsModel}. See \link{CreateInputsModel} for details} @@ -25,9 +25,15 @@ CreateRunOptions(x, ...) \item{IniStates}{(optional) \link{numeric} object or \link{list} of \link{numeric} object of class \emph{IniStates}, see \link[airGR:CreateIniStates]{airGR::CreateIniStates} for details} \item{...}{arguments passed to \link[airGR:CreateRunOptions]{airGR::CreateRunOptions}, see details} + +\item{InputsModel}{object of class \emph{InputsModel} (only used to be consistent +with the original \link[airGR:CreateRunOptions]{airGR::CreateRunOptions} which has \code{FUN_MOD} as first +parameter) +see \link[airGR:CreateInputsModel]{airGR::CreateInputsModel} for details} } \value{ -Depending on the class of \code{InputsModel} argument (respectively \emph{InputsModel} and \emph{GRiwrmInputsModel} object), the returned value is respectively: +Depending on the class of \code{InputsModel} argument (respectively +\emph{InputsModel} and \emph{GRiwrmInputsModel} object), the returned value is respectively: \itemize{ \item a \code{RunOptions} object (See \link[airGR:CreateRunOptions]{airGR::CreateRunOptions}) \item a \code{GRiwrmRunOptions} object which is a \link{list} of \code{RunOptions} objects with one item per modeled sub-catchment @@ -39,9 +45,11 @@ This function can be used either for a catchment (with an \emph{InputsModel} obj \details{ See \link[airGR:CreateRunOptions]{airGR::CreateRunOptions} documentation for a complete list of arguments. -If \code{InputsModel} argument is a \emph{GRiwrmInputsModel} object, \code{IniStates} must be a list of \link{numeric} object of class \emph{IniStates} with one item per modeled sub-catchment. +If \code{x} argument is a \emph{GRiwrmInputsModel} object, \code{IniStates} must be a +list of \link{numeric} object of class \emph{IniStates} with one item per modeled sub-catchment. -With a \emph{GRiwrmInputsModel} object, all arguments are applied on each sub-catchments of the network. +With a \emph{GRiwrmInputsModel} object, all arguments are applied on each +sub-catchments of the network. } \examples{ ###################################################################