Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
332f63e
Develop (#78)
jbousquin Sep 23, 2025
ebbeab2
Trying Jeff's epar package to generate code cov badge
mhweber Sep 23, 2025
f057869
incrementing dev version
mhweber Sep 24, 2025
b4cb12d
Metric categories (#79)
mhweber Oct 3, 2025
bdd7fed
Updating version
mhweber Oct 6, 2025
c37efca
changes to sc_get_params and lc_get_params
mhweber Oct 8, 2025
dee7c3f
fix to allow passing vectors of metric, state, county, region to both…
mhweber Oct 8, 2025
c57a9b7
remove global variables messages
michaeldumelle Oct 8, 2025
8e5e917
reconcile merge
michaeldumelle Oct 8, 2025
979ea71
couple more updates to get_params functions and adding Mike as contri…
mhweber Oct 8, 2025
7f53b7c
updated documentation
mhweber Oct 8, 2025
55dcb91
Merge branch 'master' into develop
mhweber Oct 9, 2025
49d5e23
Merge branch 'master' into develop
mhweber Oct 9, 2025
56f96cd
Increment develop branch
mhweber Oct 9, 2025
276494d
added try catch to functions to fail gracefully and fixed column sepa…
mhweber Oct 15, 2025
c867a2b
added new get_metric_names example to Vignettes and last fixes to try…
mhweber Oct 15, 2025
4a40067
document new functions
mhweber Oct 15, 2025
f70a186
updated CRAN comments
mhweber Oct 15, 2025
051c7b9
merge final CRANv0.9.0 material to develop
mhweber Oct 16, 2025
f6f3b78
Ordered vignettes in github pages
mhweber Oct 16, 2025
b5cb3ae
handling in vignettes for web service being down
mhweber Oct 20, 2025
f2110c1
updated CRAN comments
mhweber Oct 20, 2025
6279826
Updated NEWS and DESCRIPTION
mhweber Oct 20, 2025
e83eada
updated CRAN comments
mhweber Oct 20, 2025
60e4c31
Switched most vignettes to articles
mhweber Oct 24, 2025
8b9df9e
updated CRAN comments and NEWS
mhweber Oct 24, 2025
dcc6a4a
packagedown update
mhweber Nov 13, 2025
1e5fe8f
NNI functionality and vignette (#85)
mhweber Jan 28, 2026
eb18a91
updating testing and documentation for new NNI functionality
mhweber Jan 29, 2026
46b5517
a couple updates to testing
mhweber Jan 29, 2026
547333c
updates to documentation
mhweber Jan 29, 2026
ba00c39
fix malformed example in sc_get_nni
mhweber Jan 29, 2026
8f5a86d
News for v 0.10.0 release
mhweber Jan 29, 2026
6510d64
some cleanup for R checks
mhweber Jan 29, 2026
99d800b
added tidyselect to suggests
mhweber Jan 29, 2026
a8bb1b8
A couple last updates prior to CRAN minor update release
mhweber Jan 29, 2026
b6f3aea
Updates to GitHub pages for v0.10.0
mhweber Feb 2, 2026
71b38b5
My goof merge conflict
mhweber Feb 2, 2026
8b6e906
updates to new function syntax in testing
mhweber Feb 3, 2026
455df38
slight fix to test for params
mhweber Feb 3, 2026
c5cad9f
mistakenly updated this test
mhweber Feb 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: StreamCatTools
Type: Package
Title: 'StreamCatTools'
Version: 0.9.1
Version: 0.10.0
Authors@R: c(person(given = "Marc",
family = "Weber",
role = c("aut", "cre"),
Expand All @@ -10,6 +10,10 @@ Authors@R: c(person(given = "Marc",
family = "Hill",
role = "ctb",
email = "hill.ryan@epa.gov"),
person(given = "Selia",
family = "Markley",
role = "ctb",
email = "markley.selia@epa.gov"),
person(given = "Travis",
family = "Hudson",
role = "ctb",
Expand Down Expand Up @@ -39,10 +43,14 @@ Imports:
nhdplusTools,
jsonlite,
httr2,
curl (>= 6.0.0)
curl (>= 6.0.0),
ggpattern,
patchwork,
cowplot,
tigris,
ggplot2
Suggests:
dplyr,
ggplot2,
mapview,
testthat,
knitr,
Expand All @@ -53,7 +61,9 @@ Suggests:
readr,
tidyr,
stringr,
purrr
purrr,
lifecycle,
tidyselect
Encoding: UTF-8
URL: https://usepa.github.io/StreamCatTools/, https://github.com/USEPA/StreamCatTools
BugReports: https://github.com/USEPA/StreamCatTools/issues
Expand Down
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ export(lc_fullname)
export(lc_get_comid)
export(lc_get_data)
export(lc_get_metric_names)
export(lc_get_nlcd)
export(lc_get_nni)
export(lc_get_params)
export(lc_nlcd)
export(lc_plotnni)
export(sc_fullname)
export(sc_get_comid)
export(sc_get_data)
export(sc_get_metric_names)
export(sc_get_nlcd)
export(sc_get_nni)
export(sc_get_params)
export(sc_nlcd)
export(sc_plotnni)
import(ggpattern)
import(ggplot2)
importFrom(curl,curl_fetch_memory)
15 changes: 15 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
# StreamCatTools 0.10.0

- Adds new functions `sc_get_nni()` and `lc_get_nni()` for ease of access to
National Nutrient Inventory data in StreamCat
- Adds new functions `sc_plot()` and `lc_plot` for plotting nitrogen and
phosphorus budgets for watersheds
- Adds a new article describing functions for plotting National Nutrient
Inventory data in StreamCat

# StreamCatTools 0.9.1

- Handles a web service being down in testing using `testthat::skip_on_cran()`
- Converts most vignettes to articles and adds one new `Start Here` vignette
=======
# StreamCatTools 0.9.1

- Handles a web service being down in testing using `testthat::skip_on_cran()`
- Converts most vignettes to articles and adds one new `Start Here` vignette


# StreamCatTools 0.9.0

Expand Down
208 changes: 200 additions & 8 deletions R/lc_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ lc_get_data <- function(comid = NULL,
#' @title Get NLCD Data
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#' `lc_nlcd()` was renamed to `lc_get_nlcd()` to create a more consistent API.
#' Function to specifically retrieve all NLCD metrics for a given year using the StreamCat API.
#'
#' @author
Expand Down Expand Up @@ -205,23 +207,32 @@ lc_get_data <- function(comid = NULL,
#' @examples
#' \dontrun{
#'
#' df <- lc_nlcd(comid='23783629', year='2019', aoi='ws')
#'
#' df <- lc_nlcd(year='2016', aoi='cat',
#' df <- lc_nlcd(comid='23783629', year='2019', aoi='ws') # Will show a deprecation warning
#'
#' df <- lc_get_nlcd(comid='23783629', year='2019', aoi='ws')
#'
#' df <- lc_get_nlcd(year='2016', aoi='cat',
#' comid='23783629,23794487,23812618', showAreaSqKm=FALSE, showPctFull=TRUE)
#'
#' df <- lc_nlcd(year='2016', aoi='cat',
#' df <- lc_get_nlcd(year='2016', aoi='cat',
#' comid='23783629,23794487,23812618', countOnly=TRUE)
#'
#' df <- lc_nlcd(year='2016, 2019', aoi='cat,ws',
#' df <- lc_get_nlcd(year='2016, 2019', aoi='cat,ws',
#' comid='23783629,23794487,23812618')
#' }
#' @export


lc_nlcd <- function(year = '2019', aoi = NULL, comid = NULL,
showAreaSqKm = NULL, showPctFull = NULL,
countOnly = NULL) {
lc_get_nlcd <- function(year = '2019',
comid = NULL,
aoi = NULL,
showAreaSqKm = NULL,
showPctFull = NULL,
state = NULL,
county = NULL,
region = NULL,
conus = NULL,
countOnly = NULL) {
# year must be a character string.
year_chr <- as.character(year)
# split multiple years supplied as a single string into
Expand Down Expand Up @@ -282,3 +293,184 @@ lc_nlcd <- function(year = '2019', aoi = NULL, comid = NULL,
# End of function. Return a data frame.
return(final_df)
}

#' @rdname lc_get_nlcd
#' @export
#' @keywords internal
lc_nlcd <- function(year = '2019',
comid = NULL,
aoi = NULL,
showAreaSqKm = NULL,
showPctFull = NULL,
state = NULL,
county = NULL,
region = NULL,
conus = NULL,
countOnly = NULL) {
lifecycle::deprecate_warn("0.10.0", "lc_nlcd()", "lc_get_nlcd()")
lc_get_nlcd(year = '2019',
comid = NULL,
aoi = NULL,
showAreaSqKm = NULL,
showPctFull = NULL,
state = NULL,
county = NULL,
region = NULL,
conus = NULL,
countOnly = NULL)
}

#' @title Get NNI
#'
#' @description
#' Function to get all NNI data available for a given year.
#'
#' @author
#' Selia Markley
#'
#' @param year Years(s) of NNI metrics to query.
#' Only valid NNI years are accepted (1987:2017)
#' Syntax: year=<year1>,<year2>
#'
#' @param aoi Specify the area of interest described by a metric. By default, all available areas of interest
#' for a given metric are returned.
#' Syntax: areaOfInterest=<value1>,<value2>
#' Values: catchment|watershed
#'
#' @param comid Return metric information for specific COMIDs
#' Syntax: comid=<comid1>,<comid2>
#'
#' @param showAreaSqKm Return the area in square kilometers of a given area of interest.
#' The default value is true.
#' Values: true|false
#'
#' @param showPctFull Return the pctfull for each dataset. The default value is false.
#' Values: true|false
#'
#' @param countOnly Return a CSV containing only the row count (ROWCOUNT) and the column
#' count (COLUMNCOUNT) that the server expects to return in a request. The default value is false.
#' Values: true|false
#'
#' @return A tibble of desired StreamCat metrics
#' @export
#'
#' @examples\donttest{
#' df <- lc_get_nni(year='1987, 1990, 2005, 2017', aoi='cat,ws',
#' comid='23783629,23794487,23812618')
#'
#' df <- lc_get_nni(year='2015', aoi='cat',
#' comid='23783629', countOnly=TRUE)
#'
#' df <- lc_get_nni(comid='23783629', year='2011, 2012', aoi='ws')
#' }

lc_get_nni <- function(year, aoi = NULL, comid = NULL,
showAreaSqKm = TRUE, showPctFull = NULL,
countOnly = NULL) {
# year must be a character string.
year_chr <- as.character(year)
# split multiple years supplied as a single string into
# a vector of years.
year_vec <- unlist(strsplit(x = year_chr,
split = ",|, "))
# Vector of valid NNI years to check inputs against.
valid_years <- c('1987',
'1988',
'1989',
'1990',
'1991',
'1992',
'1993',
'1994',
'1995',
'1996',
'1997',
'1998',
'1999',
'2000',
'2001',
'2002',
'2003',
'2004',
'2005',
'2006',
'2007',
'2008',
'2009',
'2010',
'2011',
'2012',
'2013',
'2014',
'2015',
'2016',
'2017')
# Stop early if any of the year(s) supplied are not found in the valid
# years vec.
stopifnot(
"year must be a valid NNI year" = any(year_vec %in% valid_years)
)
# Vector of NNI metric names.
nni <- c(
'n_leg_',
'n_ags_',
'n_ff_',
'n_uf_',
'n_cf_',
'n_cr_',
'n_hw_',
'n_lw_',
'p_leg_',
'p_ags_',
'p_ff_',
'p_uf_',
'p_cr_',
'p_hw_',
'p_lw_'
)
# Add n_dep for available years
ndep_year_vec <- year_vec[!year_vec %in% c('1987', '1988', '1989')]
ndep_comb <- expand.grid('n_dep_', ndep_year_vec)
ndep_mets <- paste0(ndep_comb$Var1,
ndep_comb$Var2,
collapse = ",",
recycle0 = TRUE)
# Add p_dep for available years
pdep_year_vec <- year_vec[!year_vec %in% c('1987', '1988', '1989', '1990', '1991', '1992', '1993', '1994', '1995', '1996',
'2014', '2015', '2016', '2017')]
pdep_comb <- expand.grid('p_dep_', pdep_year_vec)
pdep_mets <- paste0(pdep_comb$Var1,
pdep_comb$Var2,
collapse = ",",
recycle0 = TRUE)
# Add n_usgsww and p_usgsww for available years
ww_year_vec <- year_vec[year_vec %in% c('1988', '1990', '1992', '1996', '2000', '2004', '2008', '2012')]
ww_comb <- expand.grid(c('p_usgsww_', 'n_usgsww_'), ww_year_vec)
ww_mets <- paste0(ww_comb$Var1,
ww_comb$Var2,
collapse = ",",
recycle0 = TRUE)
# Create a data frame of all NNI Metric and year combinations.
all_comb <- expand.grid(nni, year_vec)
# Concatenate the NLCD metric name with the supplied year(s) to create
# valid metric names to submit to the API.
nni_mets <- paste0(all_comb$Var1,
all_comb$Var2,
collapse = ",",
recycle0 = TRUE)
# Combine all NNI metrics
nni_mets_all <- paste0(nni_mets, ",", ndep_mets, ",", pdep_mets, ",", ww_mets)

# Query the API.
final_df <- lc_get_data(
metric = nni_mets_all,
aoi = aoi,
comid = comid,
showAreaSqKm = showAreaSqKm,
showPctFull = showPctFull,
countOnly = countOnly
)
# End of function. Return a data frame.
return(final_df)
}

Loading
Loading