From b879fb8a29c223bd5d852212839ec48dae1eff7c Mon Sep 17 00:00:00 2001
From: Mauricio Zambrano-Bigiarini <hzambran@users.noreply.github.com>
Date: Thu, 28 Jun 2012 14:57:03 +0000
Subject: [PATCH] Fixed error that appeared when the 'plot_out' function was
 called from an R script running directly on the OS console (not within the R
 editor), with the following error message: 'Error in plot2(x = sim, y = obs,
 plot.type = single, main = paste('Daily',  : could not find function 'hasArg'

---
 DESCRIPTION  |  4 ++--
 NAMESPACE    |  3 ++-
 NEWS         |  7 +++++++
 R/plot_out.R | 12 ++++++++----
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 329ad25..154ab03 100755
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,8 @@
 Package: hydroPSO
 Type: Package
 Title: Model-Independent Particle Swarm Optimisation for Environmental Models
-Version: 0.1-56-2
-Date: 2012-06-25
+Version: 0.1-56-3
+Date: 2012-06-28
 Author: Mauricio Zambrano-Bigiarini [aut, cre] and Rodrigo Rojas [ctb]
 Author@R: c(person("Mauricio", "Zambrano-Bigiarini", email = "mzb.devel@gmail.com", role=c("aut", "cre") ), person("Rodrigo", "Rojas", email = "Rodrigo.RojasMujica@gmail.com", role=c("ctb") ) )
 Maintainer: Mauricio Zambrano-Bigiarini <mzb.devel@gmail.com>
diff --git a/NAMESPACE b/NAMESPACE
index 8b23dec..ed5594c 100755
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,8 +1,9 @@
-#importFrom("hydroTSM", hydroplot, hydropairs, dip, mip, yip, vector2zoo)
 importFrom("Hmisc", wtd.quantile, wtd.Ecdf)
 importFrom("sp", coordinates, spplot)
 importFrom("lattice", xyplot, axis.default)
 import(grid)
+#importFrom("hydroTSM", hydroplot, hydropairs, dip, mip, yip, vector2zoo)
+#importFrom("hydroGOF", ggof)
 #importFrom("scatterplot3d", scatterplot3d)
 #exportPattern("^[^\\.]")
 export(hydroPSO,
diff --git a/NEWS b/NEWS
index 651ad33..f44cd31 100755
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,13 @@ NEWS/ChangeLog for hydroPSO
                           -) default value for the exponent of the time-varying lambda was changed from 'TVlambda.exp= 1.7' to 'TVlambda.exp= 1'.
                              However, by default 'use.TVlambda= FALSE' still.
                           -) source code was tidy up
+        o 'plot_out'    : -) Fixed error that appeared when the 'plot_out' function was called from an R script running directly on the OS console 
+                             (not within the R editor), with the following error message:
+                             "Error in plot2(x = sim, y = obs, plot.type = "single", main = paste("Daily",  : 
+                              could not find function "hasArg"
+                             Calls: plot_results -> plot_out -> ggof -> plot2"
+        o 'plot_results': -) Same as immediately above (because 'plot_results' internally calls 'plot_out')
+                           
                              
 0.1-56	14-Jun-2012
         o 'hydroPSO'    : -) much less memory consumption for large values of 'maxit' and/or 'npart' (thanks to  Paul Smith for reporting it !)
diff --git a/R/plot_out.R b/R/plot_out.R
index fa698c1..ef1ea48 100755
--- a/R/plot_out.R
+++ b/R/plot_out.R
@@ -17,7 +17,7 @@
 ################################################################################
 # Author : Mauricio Zambrano-Bigiarini                                         #  
 # Started: 03-Feb-2012                                                         #
-# Updates: 15-Feb-2012 ; 22-Feb-2012                                           #        
+# Updates: 15-Feb-2012 ; 22-Feb-2012 ; 28-Jun-2012                             #        
 ################################################################################
 
 plot_out <- function(sim, obs, 
@@ -82,6 +82,12 @@ plot_out <- function(sim, obs,
     } else if ( !(MinMax %in% c("min", "max")) )
              stop("Invalid argument: 'MinMax' must be in c('min', 'max')")
   } # IF end
+  
+  # Checking 'hydroGOF' pacakge when ptype=="ts"
+  if (ptype=="ts") {
+   if (!require(hydroGOF))
+     stop("Invalid argument: You don't have the 'hydroGOF' package => You can not use 'ptype='ts' !!")
+  } # IF end
            
   # Checking 'class(sim)'    
   if ( (ptype=="corr") | (ptype=="ts") ) {
@@ -125,9 +131,6 @@ plot_out <- function(sim, obs,
     
   } else if (ptype=="ts") {
       main="Observed vs 'best' Simulation"
-             
-      if (!require(hydroGOF))
-        stop("Invalid argument: You don't have the 'hydroGOF' package => You can not use 'ptype='ts' !!")
        
       if (!is.null(dates)) {
         if (!is.zoo(obs)) obs <- zoo(obs, dates) 
@@ -135,6 +138,7 @@ plot_out <- function(sim, obs,
       } # IF end
       
       # Plotting Sim vs Obs
+      library(hydroGOF)
       ggof(sim=sim, obs=obs, main=main, ftype=ftype, FUN=FUN, 
            cex.main=cex.main, cex.axis=cex.axis, cex.lab=cex.lab, leg.cex=leg.cex) # dates.fmt="%Y-%m-%d")
   
-- 
GitLab