diff --git a/R/plot.OutputsModel.R b/R/plot.OutputsModel.R index 9c0c4f54764cd103b7888f906cf69ddfd692bbec..fd16926141c044e2e71eda98f4f169b009c487f3 100644 --- a/R/plot.OutputsModel.R +++ b/R/plot.OutputsModel.R @@ -2,7 +2,10 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea = OutputsModel <- x - if(!inherits(OutputsModel, "GR") & !inherits(OutputsModel, "CemaNeige")){ stop(paste("OutputsModel not in the correct format for default plotting \n", sep = "")); return(NULL); } + if(!inherits(OutputsModel, "GR") & !inherits(OutputsModel, "CemaNeige")){ + stop(paste("OutputsModel not in the correct format for default plotting \n", sep = "")) + return(NULL) + } BOOL_Dates <- FALSE; if("DatesR" %in% names(OutputsModel)){ BOOL_Dates <- TRUE; } @@ -21,11 +24,22 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea = if( is.null( which)){ stop("which must be a vector of character \n"); return(NULL); } if(!is.vector( which)){ stop("which must be a vector of character \n"); return(NULL); } if(!is.character(which)){ stop("which must be a vector of character \n"); return(NULL); } - if(sum(which %in% c("all", "Precip", 'Temp', "SnowPack", "Flows", "Regime", "CumFreq", "CorQQ") == FALSE) != 0){ - cat("Incorrect element found in which \n"); - stop("which can only contain 'all', 'Precip', 'Temp', 'SnowPack', 'Flows', 'Regime', 'CumFreq' or 'CorQQ') \n"); - return(NULL); } - if("all" %in% which){ which <- c("Precip", "Temp", "SnowPack", "Flows", "Regime", "CumFreq", "CorQQ"); } + if (any(!which %in% c("all", "Precip", 'Temp', "SnowPack", "Flows", "Regime", "CumFreq", "CorQQ"))) { + stop("Incorrect element found in argument which:\nit can only contain 'all', 'Precip', 'Temp', 'SnowPack', 'Flows', 'Regime', 'CumFreq' or 'CorQQ'") + return(NULL) + } + if (all(which %in% c("Temp", "SnowPack")) & !inherits(OutputsModel, "CemaNeige")) { + stop("Incorrect element found in argument which:\nwithout CemaNeige it can only contain 'all', 'Precip', 'Flows', 'Regime', 'CumFreq' or 'CorQQ'") + return(NULL) + } + if (length(unique(which %in% c("Temp", "SnowPack"))) == 2 & !inherits(OutputsModel, "CemaNeige")) { + warning("Incorrect element found in argument which:\nit can only contain 'all', 'Precip', 'Flows', 'Regime', 'CumFreq' or 'CorQQ'\nwithout CemaNeige 'Temp' and 'SnowPack' are not available") + } + + if ("all" %in% which) { + which <- c("Precip", "Temp", "SnowPack", "Flows", "Regime", "CumFreq", "CorQQ") + } + if(!BOOL_Dates){ stop(paste("OutputsModel must contain at least DatesR to allow plotting \n", sep = "")); return(NULL); }