From 37ae6cb2b61b210a7ac4a045b6a4b00e96af51b2 Mon Sep 17 00:00:00 2001
From: unknown <ldecicco@usgs.gov>
Date: Tue, 16 Dec 2014 15:09:24 -0600
Subject: [PATCH] Simple formatting edits to pretty up the code.

---
 R/readNWISpCode.r       |  1 -
 R/readWQPqw.r           |  9 ++++++---
 R/whatNWISData.r        | 18 +++++++++---------
 man/constructNWISURL.Rd |  3 ---
 4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/R/readNWISpCode.r b/R/readNWISpCode.r
index 20773122..a2a45689 100644
--- a/R/readNWISpCode.r
+++ b/R/readNWISpCode.r
@@ -45,7 +45,6 @@ readNWISpCode <- function(parameterCd){
         newData <- importRDB1(url,asDateTime = FALSE)
       } else {
         
-        #TODO: add else...
         fullURL <- "http://nwis.waterdata.usgs.gov/nwis/pmcodes/pmcodes?radio_pm_search=param_group&pm_group=All+--+include+all+parameter+groups&format=rdb&show=parameter_group_nm&show=parameter_nm&show=casrn&show=srsname&show=parameter_units"
         fullPcodeDownload <- importRDB1(fullURL)
         newData <- fullPcodeDownload[fullPcodeDownload$parameter_cd %in% parameterCd,]
diff --git a/R/readWQPqw.r b/R/readWQPqw.r
index cf87ac9f..ac1d2e29 100644
--- a/R/readWQPqw.r
+++ b/R/readWQPqw.r
@@ -121,10 +121,12 @@ readWQPqw <- function(siteNumbers,parameterCd,startDate="",endDate=""){
   
   if(pcodeCheck){
     siteInfo <- whatWQPsites(siteid=paste0(siteNumbers,collapse=";"),
-                             pCode=paste0(parameterCd,collapse=";"), startDateLo=startDate, startDateHi=endDate)
+                             pCode=paste0(parameterCd,collapse=";"), 
+                             startDateLo=startDate, startDateHi=endDate)
   } else {
     siteInfo <- whatWQPsites(siteid=paste0(siteNumbers,collapse=";"), 
-                             characteristicName=paste0(parameterCd,collapse=";"), startDateLo=startDate, startDateHi=endDate)
+                             characteristicName=paste0(parameterCd,collapse=";"), 
+                             startDateLo=startDate, startDateHi=endDate)
   }
     
   siteInfoCommon <- data.frame(station_nm=siteInfo$MonitoringLocationName,
@@ -147,7 +149,8 @@ readWQPqw <- function(siteNumbers,parameterCd,startDate="",endDate=""){
   
   if(any(variableInfo$parameterCd != "")){
     pCodeToName <- pCodeToName
-    varExtras <- pCodeToName[pCodeToName$parm_cd %in% unique(variableInfo$parameterCd[!is.na(variableInfo$parameterCd)]),]
+    varExtras <- pCodeToName[pCodeToName$parm_cd %in% 
+                               unique(variableInfo$parameterCd[!is.na(variableInfo$parameterCd)]),]
     names(varExtras)[names(varExtras) == "parm_cd"] <- "parameterCd"
     variableInfo <- merge(variableInfo, varExtras, by="parameterCd")
   }
diff --git a/R/whatNWISData.r b/R/whatNWISData.r
index d182501a..2d9c18da 100644
--- a/R/whatNWISData.r
+++ b/R/whatNWISData.r
@@ -73,17 +73,17 @@ whatNWISdata <- function(siteNumbers,service="all",parameterCd="all",statCd="all
   }
   
   if(!("all" %in% parameterCd)){
-    parameterCdCheck <- all(nchar(parameterCd) == 5) & all(!is.na(suppressWarnings(as.numeric(parameterCd))))
-    
-    if(parameterCdCheck){
+    if(any(!is.na(parameterCd))){
+      pcodeCheck <- all(nchar(parameterCd) == 5) & all(!is.na(suppressWarnings(as.numeric(parameterCd))))
       
-      pCodeInfo <- readNWISpCode(parameterCd)
-      
-      if(nrow(pCodeInfo) != length(parameterCd)){
-        badPcodes <- parameterCd[!(parameterCd %in% pCodeInfo$parameter_cd)]
-        warning("The following parameterCds seem mistyped:",paste(badPcodes,collapse=","), "and will be ignored.")
-        parameterCd <- unique(pCodeInfo$parameter_cd)
+      if(!pcodeCheck){
+        badIndex <- which(nchar(parameterCd) != 5 | is.na(suppressWarnings(as.numeric(parameterCd))))
+        
+        stop("The following pCodes appear mistyped:",paste(parameterCd[badIndex],collapse=","))
+      } else {
+        parameterCdCheck <- readNWISpCode(parameterCd)
       }
+      
     }
   }
   
diff --git a/man/constructNWISURL.Rd b/man/constructNWISURL.Rd
index cbe2bde3..ca21f6bb 100644
--- a/man/constructNWISURL.Rd
+++ b/man/constructNWISURL.Rd
@@ -44,8 +44,6 @@ siteNumber <- '01594440'
 startDate <- '1985-01-01'
 endDate <- ''
 pCode <- c("00060","00010")
-\donttest{
-# Not running for time considerations
 url_daily <- constructNWISURL(siteNumber,pCode,
            startDate,endDate,'dv',statCd=c("00003","00001"))
 url_unit <- constructNWISURL(siteNumber,pCode,"2012-06-28","2012-06-30",'iv')
@@ -58,7 +56,6 @@ url_daily_tsv <- constructNWISURL(siteNumber,pCode,startDate,endDate,'dv',
 url_rating <- constructNWISURL(siteNumber,service="rating",ratingType="base")
 url_peak <- constructNWISURL(siteNumber, service="peak")
 url_meas <- constructNWISURL(siteNumber, service="meas")
-           }
 }
 \keyword{USGS}
 \keyword{data}
-- 
GitLab