Skip to content

Commit

Permalink
lc_get_params function
Browse files Browse the repository at this point in the history
  • Loading branch information
mhweber committed Jan 12, 2024
1 parent a9c633e commit 19c8251
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions R/lc_get_params.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#' @title Get LakeCat Parameters
#'
#' @description
#' Function to return available LakeCat parameters using the StreamCat API.
#'
#' @author
#' Marc Weber
#'
#' @param param Either name or area to grab JSON of parameters in API
#' Syntax: param=<value1>,<value2>
#' Values: name|area
#'
#' @return A list of all the current LakeCat values for a given parameter
#' @export
#'
#' @examples
#' params <- lc_get_params(param='name')
#' params <- lc_get_params(param='area')

lc_get_params <- function(param = NULL) {
resp <- jsonlite::fromJSON("https://java.epa.gov/StreamCAT/LakeCat/metrics")
if (param=='areaOfInterest') params <- resp$parameters$areaOfInterest$options else{
params <- resp$parameters$name$options
}
return(params)
}

#' @title Lookup Full Metric Name
#'
#' @description
#' Function to retrieve a full metric name based on the short name using the LakeCat API.
#'
#' @author
#' Marc Weber
#'
#' @param metric Short metric name
#' Syntax: metric=value1
#' Values: metric
#'
#' @return A lookup of the full name for a given LakeCat metric
#' @export
#'
#' @examples
#' 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]
return(result)
}

0 comments on commit 19c8251

Please sign in to comment.