From 49e93c8778bb1868e5f54d3c20ac9e4c8a2d4b84 Mon Sep 17 00:00:00 2001 From: Weber Date: Sun, 21 Apr 2024 11:04:09 -0700 Subject: [PATCH] fixes for issues 40 and 41 --- R/lc_get_params.R | 5 +++-- R/sc_get_params.R | 3 ++- tests/testthat/test-lc_get_params.R | 4 ++-- tests/testthat/test-sc_get_params.R | 6 +++--- vignettes/Introduction.Rmd | 12 +++++++++--- vignettes/LakeCat.Rmd | 13 +++++++++++++ 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/R/lc_get_params.R b/R/lc_get_params.R index 57325e2..bfaf58c 100644 --- a/R/lc_get_params.R +++ b/R/lc_get_params.R @@ -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) } @@ -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) } diff --git a/R/sc_get_params.R b/R/sc_get_params.R index 2f7f1c5..2f654d8 100644 --- a/R/sc_get_params.R +++ b/R/sc_get_params.R @@ -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) } @@ -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) } diff --git a/tests/testthat/test-lc_get_params.R b/tests/testthat/test-lc_get_params.R index f2bd500..cc4b368 100644 --- a/tests/testthat/test-lc_get_params.R +++ b/tests/testthat/test-lc_get_params.R @@ -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", { diff --git a/tests/testthat/test-sc_get_params.R b/tests/testthat/test-sc_get_params.R index a9ff8a5..ef8f4f5 100644 --- a/tests/testthat/test-sc_get_params.R +++ b/tests/testthat/test-sc_get_params.R @@ -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", { diff --git a/vignettes/Introduction.Rmd b/vignettes/Introduction.Rmd index 4396216..d0072ae 100644 --- a/vignettes/Introduction.Rmd +++ b/vignettes/Introduction.Rmd @@ -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 diff --git a/vignettes/LakeCat.Rmd b/vignettes/LakeCat.Rmd index b8bf305..f9dc800 100644 --- a/vignettes/LakeCat.Rmd +++ b/vignettes/LakeCat.Rmd @@ -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.