Newer
Older
Laura A DeCicco
committed
#' USGS data availability
#'
#' Imports a table of available parameters, period of record, and count. There is also an option to load the long parameter names and additional information on the parameters with longNames=TRUE.
Laura A DeCicco
committed
#'
#' @param siteNumber string USGS site number. This is usually an 8 digit number
#' @param interactive logical Option for interactive mode. If true, there is user interaction for error handling and data checks.
#' @param longNames logical indicates whether or not to make a web call to get long names of parameters. Be aware this could take a very long time if the station has lots of data.
Laura A DeCicco
committed
#' @keywords data import USGS web service
#' @return retval dataframe with all information found in the expanded site file
#' @export
#' @examples
#' # These examples require an internet connection to run
#' availableData <- getDataAvailablilty('05114000',interactive=FALSE)
getDataAvailablilty <- function(siteNumber="",interactive=TRUE, longNames=FALSE){
Laura A DeCicco
committed
# Checking for 8 digit site ID:
siteNumber <- formatCheckSiteNumber(siteNumber,interactive=interactive)
Laura A DeCicco
committed
urlSitefile <- paste("http://waterservices.usgs.gov/nwis/site?format=rdb&seriesCatalogOutput=true&sites=",siteNumber,sep = "")
Laura A DeCicco
committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SiteFile <- read.delim(
urlSitefile,
header = TRUE,
quote="\"",
dec=".",
sep='\t',
colClasses=c('character'),
fill = TRUE,
comment.char="#")
SiteFile <- SiteFile[-1,]
SiteFile <- with(SiteFile, data.frame(parameter_cd=parm_cd, statCd=stat_cd, startDate=begin_date,endDate=end_date, count=count_nu,service=data_type_cd,stringsAsFactors = FALSE))
SiteFile <- SiteFile[!is.na(SiteFile$parameter_cd),]
SiteFile <- SiteFile["" != SiteFile$parameter_cd,]
SiteFile$startDate <- as.Date(SiteFile$startDate)
SiteFile$endDate <- as.Date(SiteFile$endDate)
SiteFile$count <- as.numeric(SiteFile$count)
if(longNames){
pCodes <- unique(SiteFile$pCode)
numObs <- length(pCodes)
printUpdate <- floor(seq(1,numObs,numObs/100))
for (i in 1:numObs){
if (1 == i) {
pcodeINFO <- getParameterInfo(pCodes[i])
} else {
pcodeINFO <- rbind(pcodeINFO, getParameterInfo(pCodes[i]))
}
if(interactive) {
cat("Percent complete: \n")
if(i %in% printUpdate) cat(floor(i*100/numObs),"\t")
}
}
SiteFile <- merge(SiteFile,pcodeINFO,by="parameter_cd")
}
return(SiteFile)
}