Skip to content
Merged
Changes from all commits
Commits
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
25 changes: 13 additions & 12 deletions R/EQ_DomainValues.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ EQ_DomainValues <- function(domain = NULL) {
dplyr::rename(eq_param = param) |>
dplyr::arrange(eq_param)

message("EQ_DomainValues: domain list retrieved from ATTAINS.")
message("EQ_DomainValues: domain list retrieved from ATTAINS web services.")
return(eq.params)
} else {
# fallback to packaged crosswalk
Expand All @@ -92,6 +92,7 @@ EQ_DomainValues <- function(domain = NULL) {

return(eq.params)
}
}

if (!is.null(domain)) {
# check to make sure user supplied domain value is valid
Expand All @@ -102,27 +103,29 @@ EQ_DomainValues <- function(domain = NULL) {

# check to make sure user supplied domain value is valid
if (domain %in% param.cw[['param']]) {
# filter for domains which have values in web service
# get param name for web services
param.ws <- param.cw |>
dplyr::filter(.data[['attains_ws_name']] != "")
dplyr::filter(param == domain) |>
dplyr::select(attains_ws_name) |>
dplyr::pull()

# filter for domains which have values in web service
eq.params <- tryCatch(
jsonlite::fromJSON(paste0(base.url, "?domainName=", param.ws)),
error = function(e) NULL)

# check to see if user supplied domain has values in web service
if (!domain %in% param.ws[['param']]) {
if (!domain %in% param.cw[["param"]]) {
stop("EQ_DomainValues: User supplied domain value valid, but no list of allowable values is
available. Review function documentation for more information on allowable values.")
}

# remove intermediate object
rm(param.ws)

# filter crosswalk by user supplied domain value
param.filter <- param.cw |>
dplyr::filter(.data[['param']] %in% domain) |>
dplyr::select("param", "attains_ws_name", "attains_ws_field") |>
dplyr::distinct()

raw.data <- jsonlite::fromJSON(paste0(base.url, "?domainName=", param.filter[['attains_ws_name']]))

print(paste0(
"EQ_DomainValues: For ", domain, " the values in the '",
param.filter[['attains_ws_field']], "' column of the function output are the ",
Expand All @@ -132,9 +135,8 @@ EQ_DomainValues <- function(domain = NULL) {
rm(param.filter, base.url, param.cw)
}

return(raw.data)
return(eq.params)
}
}
}

#' Downloads/updates an internal copy of allowable domain values for EQ_DomainValues
Expand Down Expand Up @@ -169,4 +171,3 @@ param.cw <- utils::read.csv(system.file("extdata", "EQParamsCrosswalk.csv",

save(eq.params, file = "inst/extdata/EQ_DomainValues.rda")
}