Skip to content

Commit

Permalink
Merge pull request #74 from getwilds/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
realbp authored Mar 15, 2024
2 parents bf44abe + 6a1c190 commit 91dd098
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 139 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: cancerprof
Title: Open Cancer Informatics
Title: API Client for State Cancer Profiles
Version: 0.0.0.9000
Authors@R:
person("Brian", "Park", , "joon.brianpark@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "YOUR-ORCID-ID"))
Description: What the package does (one paragraph).
Description: An API Client for accessing data from State Cancer Profiles for programmable analysis.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(risk_women_health)
importFrom(cdlTools,fips)
importFrom(cli,cli_abort)
importFrom(dplyr,across)
importFrom(dplyr,all_of)
importFrom(dplyr,filter)
importFrom(dplyr,mutate)
importFrom(dplyr,mutate_all)
Expand Down
16 changes: 5 additions & 11 deletions R/demo-crowding.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#' \dontrun{
#' demo_crowding(
#' area = "WA",
#' areatype = "hsa",
#' areatype = "county",
#' crowding = "household with >1 person per room",
#' race = "All Races (includes Hispanic)"
#' )
Expand Down Expand Up @@ -74,19 +74,13 @@ demo_crowding <- function(area, areatype, crowding, race) {

resp <- process_resp(resp, "demographics")

areatype_map <- c(
"county" = "County", "hsa" = "Health_Service_Area",
"state" = "State"
)
areacode_map <- c("county" = "FIPS", "state" = "FIPS", "hsa" = "HSA_Code")

areatype_title <- areatype_map[areatype]
areacode_title <- areacode_map[areatype]
area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
"Percent",
"Households",
"Rank"
Expand Down
17 changes: 5 additions & 12 deletions R/demo-education.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,14 @@ demo_education <- function(area, areatype, education, sex = NULL, race = NULL) {
req_perform()

resp <- process_resp(resp, "demographics")

areatype_map <- c(
"county" = "County",
"hsa" = "Health_Service_Area",
"state" = "State"
)
areacode_map <- c("county" = "FIPS", "state" = "FIPS", "hsa" = "HSA_Code")

areatype_title <- areatype_map[areatype]
areacode_title <- areacode_map[areatype]

area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
"Percent",
"Households",
"Rank"
Expand Down
11 changes: 5 additions & 6 deletions R/demo-food-access.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,18 @@ demo_food <- function(area, areatype, food, race = NULL) {
resp <- req_draft %>%
req_perform()

resp <- process_resp(resp, "demographics") %>%
mutate(Value..Percent. = as.integer(Value..Percent.))
resp <- process_resp(resp, "demographics")

areatype_map <- c("county" = "County", "state" = "State")
areatype_title <- areatype_map[areatype]
area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

if (food == "limited access to healthy food") {
resp %>%
setNames(c(areatype_title, "FIPS", "Percent", "People")) %>%
setNames(c(area_type, area_code, "Percent", "People")) %>%
mutate(across(c("Percent", "People"), \(x) as.numeric(x)))
} else if (food == "food insecurity") {
resp %>%
setNames(c(areatype_title, "FIPS", "Percent")) %>%
setNames(c(area_type, area_code, "Percent")) %>%
mutate(across(c("Percent"), \(x) as.numeric(x)))
}
}
9 changes: 4 additions & 5 deletions R/demo-income.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,12 @@ demo_income <- function(area, areatype, income, race) {
) %>%
req_perform()

resp <- process_resp(resp, "demographics") %>%
mutate(Value..Dollars. = as.integer(Value..Dollars.))
resp <- process_resp(resp, "demographics")

areatype_map <- c("county" = "County", "state" = "State")
areatype_title <- areatype_map[areatype]
area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

resp %>%
setNames(c(areatype_title, "FIPS", "Dollars", "Rank")) %>%
setNames(c(area_type, area_code, "Dollars", "Rank")) %>%
mutate(across(c("Dollars"), \(x) as.numeric(x)))
}
13 changes: 3 additions & 10 deletions R/demo-insurance.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,10 @@ demo_insurance <- function(area, areatype, insurance, sex, age, race = NULL) {

resp <- process_resp(resp, "demographics")

areatype_map <- c(
"county" = "County",
"hsa" = "Health_Service_Area",
"state" = "State"
)
areatype_title <- areatype_map[areatype]

areacode_map <- c("county" = "FIPS", "state" = "FIPS", "hsa" = "HSA_Code")
areacode_title <- areacode_map[areatype]
area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

resp %>%
setNames(c(areatype_title, areacode_title, "Percent", "People", "Rank")) %>%
setNames(c(area_type, area_code, "Percent", "People", "Rank")) %>%
mutate(across(c("Percent", "People"), \(x) as.numeric(x)))
}
15 changes: 4 additions & 11 deletions R/demo-mobility.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,13 @@ demo_mobility <- function(area, areatype, mobility) {

resp <- process_resp(resp, "demographics")

areatype_map <- c(
"county" = "County",
"hsa" = "Health_Service_Area",
"state" = "State"
)
areatype_title <- areatype_map[areatype]

areacode_map <- c("county" = "FIPS", "state" = "FIPS", "hsa" = "HSA_Code")
areacode_title <- areacode_map[areatype]
area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
"Percent",
"People",
"Rank"
Expand Down
16 changes: 4 additions & 12 deletions R/demo-non-english-language.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,13 @@ demo_language <- function(area, areatype, language) {

resp <- process_resp(resp, "demographics")

areatype_map <- c(
"county" = "County",
"hsa" = "Health_Service_Area",
"state" = "State"
)

areatype_title <- areatype_map[areatype]

areacode_map <- c("county" = "FIPS", "state" = "FIPS", "hsa" = "HSA_Code")
areacode_title <- areacode_map[areatype]
area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
"Percent",
"Households",
"Rank"
Expand Down
15 changes: 4 additions & 11 deletions R/demo-population.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,13 @@ demo_population <- function(area, areatype, population, race = NULL, sex = NULL)

resp <- process_resp(resp, "demographics")

areatype_map <- c(
"county" = "County",
"hsa" = "Health_Service_Area",
"state" = "State"
)
areatype_title <- areatype_map[areatype]

areacode_map <- c("county" = "FIPS", "state" = "FIPS", "hsa" = "HSA_Code")
areacode_title <- areacode_map[areatype]
area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
"Percent",
"People",
"Rank"
Expand Down
19 changes: 6 additions & 13 deletions R/demo-poverty.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,21 @@ demo_poverty <- function(area, areatype, poverty, race = NULL, sex = NULL) {

resp <- process_resp(resp, "demographics")

areatype_map <- c(
"county" = "County",
"hsa" = "Health_Service_Area",
"state" = "State"
)
areatype_title <- areatype_map[areatype]

areacode_map <- c("county" = "FIPS", "state" = "FIPS", "hsa" = "HSA_Code")
areacode_title <- areacode_map[areatype]
area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

if (poverty == "persistent poverty") {
resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
"Persistent Poverty"
))
} else {
resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
"Percent",
"People",
"Rank"
Expand Down
15 changes: 4 additions & 11 deletions R/demo-workforce.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,13 @@ demo_workforce <- function(area, areatype, workforce, race, sex) {

resp <- process_resp(resp, "demographics")

areatype_map <- c(
"county" = "County",
"hsa" = "Health_Service_Area",
"state" = "State"
)
areatype_title <- areatype_map[areatype]

areacode_map <- c("county" = "FIPS", "state" = "FIPS", "hsa" = "HSA_Code")
areacode_title <- areacode_map[areatype]
area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
"Percent",
"People_Unemployed",
"Rank"
Expand Down
28 changes: 10 additions & 18 deletions R/incidence-cancer.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#' @importFrom httr2 req_url_query req_perform
#' @importFrom cli cli_abort
#' @importFrom stats setNames
#' @importFrom dplyr mutate across
#' @importFrom dplyr mutate across all_of
#'
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Age Adjusted Incidence Rate, Lower 95% CI,
Expand Down Expand Up @@ -174,17 +174,9 @@ incidence_cancer <- function(area, areatype, cancer, race, sex, age, stage, year
req_perform()

resp <- process_resp(resp, "incidence")


areatype_map <- c(
"county" = "County",
"hsa" = "Health Service Area",
"state" = "State"
)
areatype_title <- areatype_map[areatype]

areacode_map <- c("county" = "FIPS", "state" = "FIPS", "hsa" = "HSA_Code")
areacode_title <- areacode_map[areatype]

area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

shared_names_to_numeric <- c(
"Age_Adjusted_Incidence_Rate",
Expand All @@ -198,8 +190,8 @@ incidence_cancer <- function(area, areatype, cancer, race, sex, age, stage, year
if (stage == "all stages") {
resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
shared_names_to_numeric,
"Annual_Average_Count",
"Recent_Trend",
Expand All @@ -208,22 +200,22 @@ incidence_cancer <- function(area, areatype, cancer, race, sex, age, stage, year
"Trend_Upper_95%_CI"
)) %>%
mutate(across(c(
shared_names_to_numeric,
all_of(shared_names_to_numeric),
"Recent_5_Year_Trend",
"Trend_Lower_95%_CI",
"Trend_Upper_95%_CI"
), \(x) as.numeric(x)))
} else if (stage == "late stage (regional & distant)") {
resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
shared_names_to_numeric,
"Annual_Average_Count",
"Percentage_of_Cases_with_Late_Stage"
)) %>%
mutate(across(c(
shared_names_to_numeric,
all_of(shared_names_to_numeric),
"Percentage_of_Cases_with_Late_Stage"
), \(x) as.numeric(x)))
}
Expand Down
19 changes: 6 additions & 13 deletions R/mortality-cancer.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#' @importFrom httr2 req_url_query req_perform
#' @importFrom cli cli_abort
#' @importFrom stats setNames
#' @importFrom dplyr mutate across
#' @importFrom dplyr mutate across all_of
#'
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Met Healthy People Objective of ***?,
Expand Down Expand Up @@ -154,15 +154,8 @@ mortality_cancer <- function(area, areatype, cancer, race, sex, age, year) {

resp <- process_resp(resp, "mortality")

areatype_map <- c(
"county" = "County",
"hsa" = "Health_Service_Area",
"state" = "State"
)
areatype_title <- areatype_map[areatype]

areacode_map <- c("county" = "FIPS", "state" = "FIPS", "hsa" = "HSA_Code")
areacode_title <- areacode_map[areatype]
area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]

names_to_numeric <- c(
"Age_Adjusted_Death_Rate",
Expand All @@ -175,8 +168,8 @@ mortality_cancer <- function(area, areatype, cancer, race, sex, age, year) {

resp %>%
setNames(c(
areatype_title,
areacode_title,
area_type,
area_code,
"Met Healthy People Objective of ***?",
"Age_Adjusted_Death_Rate",
"Lower_95%_CI_Rate",
Expand All @@ -191,7 +184,7 @@ mortality_cancer <- function(area, areatype, cancer, race, sex, age, year) {
"Upper_95%_CI_Trend"
)) %>%
mutate(across(c(
names_to_numeric,
all_of(names_to_numeric),
"Recent_5_Year_Trend",
"Lower_95%_CI_Trend",
"Upper_95%_CI_Trend"
Expand Down
Loading

0 comments on commit 91dd098

Please sign in to comment.