DOI-USGS / dataRetrieval

This R package is designed to obtain USGS or EPA water quality sample data, streamflow data, and metadata directly from web services.
https://doi-usgs.github.io/dataRetrieval/
Other
259 stars 84 forks source link

using readNWISuv for 80 site numbers altogether #488

Closed deleteblue closed 4 years ago

deleteblue commented 4 years ago

I have a list of site numbers and I want to use readNWISuv. But I does not recognize it. How can I fix this issue?

siteno <- list( read.csv(path)) q <- readNWISuv( siteNumbers = siteno, "00060", "2015-10-10", "2015-10-11")

This is the error I get Request failed [400]. Retrying in 1 seconds... Request failed [400]. Retrying in 2.5 seconds... Error in getWebServiceData(obs_url, encoding = "gzip") : HTTP Status 400 - unrecognized character in input sequence: position=[4]

ldecicco-USGS commented 4 years ago

I think you probably have the site numbers formatted wrong. If it's a csv that looks like this:

Sites,
04024430,
04024000,
05114000

Then, to get a vector of site ids, you'd want to do:

siteno <- read.csv(path, 
                   colClasses = "character",
                   stringsAsFactors = FALSE)[["Sites"]]
siteno
[1] "04024430" "04024000" "05114000"
q <- readNWISuv( siteNumbers = siteno, "00060", "2015-10-10", "2015-10-11")

If your sites are like this:

04024430,04024000,05114000

Then the call to get the site vector would be:

siteno <- as.character(read.csv("test.csv", header = FALSE,
                   colClasses = "character",
                   stringsAsFactors = FALSE)[1,])

If you want to paste a bit of your csv, I might be able to help more if the above doesn't solve it.

deleteblue commented 4 years ago

Yes! That was the problem! And now it is solved! Thank you!