Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Water
dataRetrieval
Commits
8a4c511e
Commit
8a4c511e
authored
Feb 11, 2022
by
Laura A DeCicco
Browse files
Fixes #564
parent
5db2c89e
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
R/readNWISdata.r
View file @
8a4c511e
...
...
@@ -276,21 +276,22 @@ countyCdLookup <- function(state, county, outputType = "id"){
stop
(
"No county code provided"
)
}
if
(
length
(
state
)
>
1
){
stop
(
"Only one state allowed in countyCdLookup."
)
}
#first turn state into stateCd postal name
stateCd
<-
stateCdLookup
(
state
,
outputType
=
"postal"
)
state_counties
<-
countyCd
[
countyCd
$
STUSAB
==
stateCd
,]
if
(
is.numeric
(
county
)
|
!
is.na
(
suppressWarnings
(
as.numeric
(
county
)))){
county_i
<-
which
(
as.numeric
(
county
)
==
as.numeric
(
countyCd
$
COUNTY
)
&
stateCd
==
countyCd
$
STUSAB
)
}
else
{
# if no suffix was added, this will figure out what it should be (or throw a helpful error)
allSuffixes
<-
unique
(
tolower
(
unlist
(
lapply
(
strsplit
(
count
yCd
$
COUNTY_NAME
,
split
=
" "
),
tail
,
1
))
))
county_in_state
<-
grep
(
tolower
(
county
),
tolower
(
state_
count
ies
$
COUNTY_NAME
))
county_i
<-
unlist
(
lapply
(
allSuffixes
,
function
(
suffix
,
stateCd
,
county
){
currentSuffixExistsInString
<-
grepl
(
paste0
(
'(?i)\\'
,
suffix
,
'$'
),
tolower
(
county
))
retCounty
<-
ifelse
(
currentSuffixExistsInString
,
county
,
paste
(
county
,
suffix
))
retCounty_i
<-
which
(
tolower
(
retCounty
)
==
tolower
(
countyCd
$
COUNTY_NAME
)
&
stateCd
==
countyCd
$
STUSAB
)
return
(
retCounty_i
)
},
stateCd
,
county
))
county_i
<-
which
(
countyCd
$
STUSAB
==
stateCd
&
countyCd
$
COUNTY_NAME
==
state_counties
$
COUNTY_NAME
[
county_in_state
]
)
if
(
length
(
county_i
)
==
0
){
stop
(
paste
(
"Could not find"
,
county
,
"(county),"
,
stateCd
,
...
...
R/readWQPdata.R
View file @
8a4c511e
...
...
@@ -129,9 +129,9 @@
#' querySummary=TRUE)
#'
#' # querying by county
#'
dailyLexingtonVA
<- readWQPdata(statecode = "
Virginia
",
#'
countycode=
"Lexington
",
#'
p
ara
me
ter
Cd = "00010
")
#'
DeWitt
<- readWQPdata(statecode = "
Illinois
",
#' countycode=
"DeWitt
",
#'
ch
ara
c
ter
isticName = "Nitrogen
")
#'
#' # Data profiles: "Organization Data"
#' org_data <- readWQPdata(statecode = "WI",
...
...
R/sysdata.rda
View file @
8a4c511e
No preview for this file type
R/tabbedDataRetrievals.R
View file @
8a4c511e
...
...
@@ -86,8 +86,9 @@ NULL
#' US State Code Lookup Table
#'
#' Data pulled from \url{https://www2.census.gov/geo/docs/reference/state.txt}
#' on April 1, 2015.
#' Data originally pulled from \url{https://www2.census.gov/geo/docs/reference/state.txt}
#' on April 1, 2015. On Feb. 11, 2022, the fields were updated with the
#' file found in inst/extdata, which is used internally with NWIS retrievals.
#'
#' @name stateCd
#' @return stateCd data frame.
...
...
@@ -108,8 +109,9 @@ NULL
#' US County Code Lookup Table
#'
#' Data pulled from \url{https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt}
#' on April 1, 2015.
#' Data originally pulled from \url{https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt}
#' on April 1, 2015. On Feb. 11, 2022, the fields were updated with the
#' file found in inst/extdata, which is used internally with NWIS retrievals.
#'
#' @name countyCd
#' @return countyCd data frame.
...
...
@@ -127,4 +129,38 @@ NULL
#' @keywords USGS countyCd
#' @examples
#' head(countyCd)
NULL
\ No newline at end of file
NULL
# x <- jsonlite::read_json("inst/extdata/state_county.json")
# states <- x[["US"]]
# state_df <- data.frame("STATE" = names(sapply(states$state_cd, function(x) x[[1]])),
# "STATE_NAME" = as.character(sapply(states$state_cd, function(x) x[[1]])))
# library(dplyr)
# state_df <- state_df %>%
# left_join(stateCd, by = c("STATE", "STATE_NAME"))
# state_df$STUSAB[state_df$STATE_NAME == "Virgin Islands"] <- "VI"
#
# y <- sapply(states$state_cd, function(x) x[["county_cd"]])
#
# county_df <- data.frame()
#
# for(st in state_df$STATE){
# county_nums <- names(y[[st]])
# county_names <- as.character(unlist(y[[st]]))
# county_df_st <- data.frame(STATE = st,
# COUNTY = county_nums,
# COUNTY_NAME = county_names)
# county_df <- dplyr::bind_rows(county_df, county_df_st)
# }
#
# county_df_full <- county_df %>%
# left_join(select(state_df, STUSAB, STATE), by = "STATE") %>%
# left_join(select(countyCd, STATE, STUSAB, COUNTY, COUNTY_ID),
# by = c("STATE", "STUSAB", "COUNTY"))
#
# countyCd <- county_df_full
# stateCd <- state_df
# save(countyCd, stateCd, parameterCdFile, pCodeToName,
# file = "sysdata.rda", compress = "xz")
inst/extdata/state_county.json
0 → 100644
View file @
8a4c511e
This diff is collapsed.
Click to expand it.
man/countyCd.Rd
View file @
8a4c511e
...
...
@@ -17,8 +17,9 @@ COUNTY_ID \tab character \tab County id \cr
}
}
\description{
Data pulled from \url{https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt}
on April 1, 2015.
Data originally pulled from \url{https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt}
on April 1, 2015. On Feb. 11, 2022, the fields were updated with the
file found in inst/extdata, which is used internally with NWIS retrievals.
}
\examples{
head(countyCd)
...
...
man/readWQPdata.Rd
View file @
8a4c511e
...
...
@@ -142,9 +142,9 @@ wqp.summary_WI <- readWQPdata(arg_3, statecode="WI",
querySummary=TRUE)
# querying by county
dailyLexingtonVA
<- readWQPdata(statecode = "
Virginia
",
countycode=
"Lexington
",
p
ara
me
ter
Cd = "00010
")
DeWitt
<- readWQPdata(statecode = "
Illinois
",
countycode=
"DeWitt
",
ch
ara
c
ter
isticName = "Nitrogen
")
# Data profiles: "Organization Data"
org_data <- readWQPdata(statecode = "WI",
...
...
man/stateCd.Rd
View file @
8a4c511e
...
...
@@ -16,8 +16,9 @@ STATENS \tab character \tab Geographic Names Information System Identifier (GNI
}
}
\description{
Data pulled from \url{https://www2.census.gov/geo/docs/reference/state.txt}
on April 1, 2015.
Data originally pulled from \url{https://www2.census.gov/geo/docs/reference/state.txt}
on April 1, 2015. On Feb. 11, 2022, the fields were updated with the
file found in inst/extdata, which is used internally with NWIS retrievals.
}
\examples{
head(stateCd)
...
...
tests/testthat/tests_userFriendly_fxns.R
View file @
8a4c511e
...
...
@@ -194,7 +194,7 @@ test_that("state county tests",{
name
<-
countyCdLookup
(
state
=
"OH"
,
county
=
13
,
output
=
"fullName"
)
expect_equal
(
name
,
"Belmont County"
)
index
<-
countyCdLookup
(
state
=
"Pennsylvania"
,
county
=
"ALLEGHENY COUNTY"
,
output
=
"tableIndex"
)
expect_equal
(
index
,
22
46
)
expect_equal
(
index
,
22
58
)
fromIDs
<-
countyCdLookup
(
state
=
13
,
county
=
5
,
output
=
"fullName"
)
expect_equal
(
fromIDs
,
"Bacon County"
)
counties
<-
c
(
"51001"
,
"51003"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment