Skip to content

Commit

Permalink
Fixes for Rcmd checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mhweber committed Jan 2, 2025
1 parent 4b7932a commit 3e78cc1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: StreamCatTools
Type: Package
Title: Tools to work with the StreamCat API within R and access the full suite of StreamCat and LakeCat metrics.
Title: Tools to work with the StreamCat API within R and access the full suite of StreamCat and LakeCat metrics
Version: 0.3.0
Authors@R: c(person(given = "Marc",
family = "Weber",
Expand Down Expand Up @@ -35,7 +35,8 @@ Suggests:
xml2,
magrittr,
readr,
tidyr
tidyr,
stringr
Encoding: UTF-8
URL: https://usepa.github.io/StreamCatTools/, https://github.com/USEPA/StreamCatTools
VignetteBuilder: knitr,rmarkdown
Expand Down
6 changes: 5 additions & 1 deletion R/lc_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ lc_get_data <- function(metric = NULL,
httr2::resp_body_string() |>
jsonlite::fromJSON()
# End of function. Return a data frame.
return(df$items)
if (is.null(countOnly)){
df <- df$items |>
dplyr::select(comid, dplyr::everything())
return(df)
} else return(df$items)
}

#' @title Get NLCD Data
Expand Down
13 changes: 8 additions & 5 deletions R/sc_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
#' showAreaSqKm=TRUE, showPctFull=TRUE)
#'
#' df <- sc_get_data(metric='pcturbmd2006,damdens',
#' aoi='cat,ws', comid='179,1337,1337420', countOnly=TRUE)
#' aoi='cat,ws', comid='179,1337,1337420', countOnly='true')
#'
#' df <- sc_get_data(metric='ThalwagDepth', comid='179,1337,1337420')
#' df <- sc_get_data(metric='ThalwagDepth', comid='179,1337,1337420',aoi='other')
#' }
#' @export

Expand Down Expand Up @@ -104,7 +104,6 @@ sc_get_data <- function(comid = NULL,
if (stringr::str_detect(aoi,'riparian_watershed')) {
aoi <- gsub('riparian_watershed','wsrp100',aoi)
}
if (aoi == 'other') aoi <- NULL
}
if ((is.null(comid) & is.null(state) & is.null(county) & is.null(region) & is.null(conus)) | is.null(metric) |is.null(aoi)){
stop('Must provide at a minimum valid comid, metric and aoi to the function')
Expand All @@ -125,8 +124,12 @@ sc_get_data <- function(comid = NULL,
# extract response body as string
httr2::resp_body_string() |>
jsonlite::fromJSON()
# End of function. Return a data frame.
return(df$items)
# End of function. Return a data frame.
if (is.null(countOnly)){
df <- df$items |>
dplyr::select(comid, dplyr::everything())
return(df)
} else return(df$items)
}

#' @title Get NLCD Data
Expand Down
2 changes: 1 addition & 1 deletion R/sc_get_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sc_get_params <- function(param = NULL) {
resp <- jsonlite::fromJSON("https://api.epa.gov/StreamCat/streams/metrics")$items
if (param=='areaOfInterest'){
params <- strsplit(stringr::str_sub(resp$aoi_param_info[[1]]$options,2,-2),",")[[1]]
params <- gsub(" ","", params)
params <- c(gsub(" ","", params),'other')
} else {
params <- resp$name_options[[1]][[1]]
}
Expand Down
4 changes: 2 additions & 2 deletions man/sc_get_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-sc_get_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ context("Test that sc_get_params is pulling in StreamCat API parameters")
test_that("sc_get_params for region parameters", {
params <- sc_get_params(param='areaOfInterest')
expect_true(exists("params"))
expect_equal(params,c("cat","catrp100","ws","wsrp100"))
expect_equal(params,c("cat","catrp100","other","ws","wsrp100"))
})

test_that("sc_get_params for name parameters", {
Expand Down

0 comments on commit 3e78cc1

Please sign in to comment.