Skip to content

Commit

Permalink
Merge pull request #42 from USEPA/names_fix
Browse files Browse the repository at this point in the history
Fixes for issues #40 and #41
  • Loading branch information
mhweber authored Apr 22, 2024
2 parents e732920 + 49e93c8 commit 325fb1d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
5 changes: 3 additions & 2 deletions R/lc_get_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lc_get_params <- function(param = NULL) {
if (param=='areaOfInterest') params <- resp$parameters$areaOfInterest$options else{
params <- resp$parameters$name$options
}
params <- params[order(params)]
return(params)
}

Expand All @@ -44,7 +45,7 @@ lc_get_params <- function(param = NULL) {
#' fullname <- lc_fullname(metric='name')

lc_fullname <- function(metric = NULL) {
resp <- as.data.frame(jsonlite::fromJSON("https://java.epa.gov/StreamCAT/LakeCat/metrics/datadictionary"))
result <- resp[resp$dictionary.metric_prefix==metric,1]
resp <- as.data.frame(jsonlite::fromJSON("https://java.epa.gov/StreamCAT/metrics/datadictionary"))
result <- resp[resp$dictionary.metric_prefix %in% unlist(strsplit(metric, split = ',')), 1]
return(result)
}
3 changes: 2 additions & 1 deletion R/sc_get_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sc_get_params <- function(param = NULL) {
if (param=='areaOfInterest') params <- resp$parameters$areaOfInterest$options else{
params <- resp$parameters$name$options
}
params <- params[order(params)]
return(params)
}

Expand All @@ -45,6 +46,6 @@ sc_get_params <- function(param = NULL) {

sc_fullname <- function(metric = NULL) {
resp <- as.data.frame(jsonlite::fromJSON("https://java.epa.gov/StreamCAT/metrics/datadictionary"))
result <- resp[resp$dictionary.metric_prefix==metric,1]
result <- resp[resp$dictionary.metric_prefix %in% unlist(strsplit(metric, split = ',')), 1]
return(result)
}
4 changes: 2 additions & 2 deletions tests/testthat/test-lc_get_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ context("Test that lc_get_params is pulling in StreamCat API parameters")
test_that("lc_get_params for region parameters", {
params <- lc_get_params(param='areaOfInterest')
expect_true(exists("params"))
expect_equal(params,c("catchment","watershed",
expect_equal(params,c("catchment","other",
"riparian_catchment",
"riparian_watershed","other"))
"riparian_watershed","watershed"))
})

test_that("lc_get_params for name parameters", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-sc_get_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ 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("catchment","watershed",
"riparian_catchment",
"riparian_watershed","other"))
expect_equal(params,c("catchment","other",
"riparian_catchment",
"riparian_watershed","watershed"))
})

test_that("sc_get_params for name parameters", {
Expand Down
12 changes: 9 additions & 3 deletions vignettes/Introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@ print(paste0('region parameters are: ', paste(region_params,collapse = ', ')))
print(paste0('A selection of available StreamCat metrics include: ',paste(name_params[1:10],collapse = ', ')))
```

Look up the display name for a metric using the `sc_fullname` function via the API
```{r Example_One_fullnames}
Look up the display name or names for a metric using the `sc_fullname` function via the API
```{r fullnames}
metric='pcthbwet2011'
fullname <- sc_fullname(metric)
print(paste0('The full name for ',metric, ' is: ', paste(fullname,collapse = ', ')))
fullname
```

```{r fullnames2}
metric='pctdecid2019,fert'
fullname <- sc_fullname(metric)
fullname
```

## Get data for COMIDs
Expand Down
13 changes: 13 additions & 0 deletions vignettes/LakeCat.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ print(paste0('region parameters are: ', paste(region_params,collapse = ', ')))
print(paste0('A selection of available LakrCat metrics include: ',paste(name_params[1:10],collapse = ', ')))
```

Look up the display name or names for a metric using the `lc_fullname` function via the API
```{r fullnames}
metric='pcthbwet2011'
fullname <- lc_fullname(metric)
fullname
```

```{r fullnames2}
metric='pctdecid2019,fert'
fullname <- lc_fullname(metric)
fullname
```

## Get data for COMIDs

In this example we access several variables, for several areas of interest, and for several COMIDs using the `lc_get_data` function. Loads data into a tibble we can view.
Expand Down

0 comments on commit 325fb1d

Please sign in to comment.