Skip to content

Commit

Permalink
Merge pull request #103 from getwilds/get-metadata-function
Browse files Browse the repository at this point in the history
edited get metadata functions
  • Loading branch information
realbp authored Apr 19, 2024
2 parents b97e835 + 03c527c commit 65f70b3
Show file tree
Hide file tree
Showing 17 changed files with 385 additions and 71 deletions.
42 changes: 42 additions & 0 deletions R/browse-trend.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# https://statecancerprofiles.cancer.gov/historicaltrend/index.php?0&9953&999&7599&136&071&48&2&0&0&1&1&1&1#results
#
# req_url_query(https://statecancerprofiles.cancer.gov/historicaltrend/index.php?0&9953&999&7599&136&071&48&2&0&0&1&1&1&1&6) %>%
# req_perform()
#
# browseURL(paste0(https://statecancerprofiles.cancer.gov/historicaltrend/index.php?0&9953&999&7599&136&071&48&2&0&0&1&1&1&1#results))
#
#
#
# req <- "https://statecancerprofiles.cancer.gov/historicaltrend/index.php"
#
# api_arguments <- "0&9953&999&7599&136&071&48&2&0&0&1&1&1&1&6"
#
# resp <- req %>%
# req_url_query(
# stateFIPS = fips_scp(area),
# areatype = tolower(areatype),
# topic = "crowd",
# demo = handle_crowding(crowding),
# race = handle_race(race),
# type = "manyareacensus",
# sortVariableName = "value",
# sortOrder = "default",
# output = 1
# ) %>%
# req_perform()
#
#
# test_ur_fail <- "https://statecancerprofiles.cancer.gov/historicaltrend/index.php?0&9953&999&7599&136&071&48&2&0&0&1&1&1&1&6"
# req <- "https://statecancerprofiles.cancer.gov/historicaltrend/data.php/historicaltrend.csv?0&9953&999&7599&136&071&07&2&0&0&1&1&1&1&6"
# req <- request("https://statecancerprofiles.cancer.gov/historicaltrend/index.php?0&9953&999&7599&136&071&48&2&0&0&1&1&1&1&6")
#
# resp <- req %>%
# req_perform() %>%
# resp_body_string()
#
#
# if (httr2::resp_content_type(resp) != "text/csv") {
# cli_abort("Invalid input, please check documentation for valid arguments.")
# }


4 changes: 3 additions & 1 deletion R/demo-crowding.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ demo_crowding <- function(area, areatype, crowding, race) {
) %>%
req_perform()

resp_url <- resp$url

resp <- process_resp(resp, "demographics")

resp$data <- resp$data %>%
Expand All @@ -80,5 +82,5 @@ demo_crowding <- function(area, areatype, crowding, race) {
)) %>%
mutate(across(c("Percent", "Households"), \(x) as.numeric(x)))

process_metadata(resp)
process_metadata(resp, "demographics", resp_url)
}
4 changes: 3 additions & 1 deletion R/demo-education.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ demo_education <- function(area, areatype, education, sex = NULL, race = NULL) {

resp <- resp %>%
req_perform()

resp_url <- resp$url

resp <- process_resp(resp, "demographics")

Expand All @@ -100,6 +102,6 @@ demo_education <- function(area, areatype, education, sex = NULL, race = NULL) {
)) %>%
mutate(across(c("Percent", "Households"), \(x) as.numeric(x)))

process_metadata(resp)
process_metadata(resp, "demographics", resp_url)

}
4 changes: 3 additions & 1 deletion R/demo-population.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ demo_population <- function(area, areatype, population, race = NULL, sex = NULL)

resp <- process_resp(resp, "demographics")

resp %>%
resp$data %>%
setNames(c(
get_area(areatype),
"Percent",
"People",
"Rank"
)) %>%
mutate(across(c("Percent", "People"), \(x) as.numeric(x)))

process_metadata(resp)
}
4 changes: 3 additions & 1 deletion R/demo-svi.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ demo_svi <- function(area, svi) {

resp <- process_resp(resp, "demographics")

resp %>%
resp$data %>%
setNames(c("County", "FIPS", "Score")) %>%
mutate(across(c("Score"), \(x) as.numeric(x)))

process_metadata(resp)
}
Loading

0 comments on commit 65f70b3

Please sign in to comment.