Skip to content

Commit

Permalink
more linting and triple zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
realbp committed Mar 7, 2024
1 parent cc4ffd1 commit 3b58631
Show file tree
Hide file tree
Showing 39 changed files with 772 additions and 241 deletions.
6 changes: 5 additions & 1 deletion R/demo-education.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ demo_education <- function(area, areatype, education, sex = NULL, race = NULL) {

resp <- process_response(resp)

areatype_map <- c("county" = "County", "hsa" = "Health_Service_Area", "state" = "State")
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]
Expand Down
18 changes: 13 additions & 5 deletions R/demo-insurance.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Access to Insurance Data
#'
#' This function returns a data frame about insurance demographics from State Cancer Profiles.
#' This function returns a data frame about insurance demographics
#' from State Cancer Profiles.
#'
#' @param area A state/territory abbreviation or USA.
#' @param areatype One of the following values:
Expand All @@ -24,15 +25,17 @@
#' - `"both sexes"`
#' - `"male"`
#' - `"female"`.
#' @param age If you specified `"both sexes"` for `sex` choose one of the following values:
#' @param age If you specified `"both sexes"` for `sex`
#' choose one of the following values:
#' - `"under 19 years"`
#' - `"18 to 64 years"`
#' - `"21 to 64 years"`
#' - `"40 to 64 years"`
#' - `"50 to 64 years"`
#' - `"under 65 years"`.
#'
#' Otherwise if you specified `"male"` or `"female"` for `sex`, choose one of the following values:
#' Otherwise if you specified `"male"` or `"female"` for `sex`,
#' choose one of the following values:
#' - `"18 to 64 years"`
#' - `"40 to 64 years"`
#' - `"50 to 64 years"`
Expand All @@ -48,7 +51,8 @@
#' @importFrom httr2 req_url_query req_perform
#' @importFrom cli cli_abort
#'
#' @returns A data frame with the following columns: Area Type, Area Code, Percent, People, Rank.
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Percent, People, Rank.
#'
#' @export
#'
Expand Down Expand Up @@ -125,7 +129,11 @@ demo_insurance <- function(area, areatype, insurance, sex, age, race = NULL) {

resp <- process_response(resp)

areatype_map <- c("county" = "County", "hsa" = "Health_Service_Area", "state" = "State")
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")
Expand Down
63 changes: 52 additions & 11 deletions R/incidence-cancer.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Access to Cancer Incident Data
#'
#' This function returns a data frame about cancer incidence from State Cancer Profiles.
#' This function returns a data frame about cancer incidence
#' from State Cancer Profiles.
#'
#' @param area A state/territory abbreviation or USA.
#' @param areatype One of the following values:
Expand Down Expand Up @@ -57,9 +58,10 @@
#' - `"latest 5 year average"`
#' - `"latest single year (us by state)"`.
#'
#' @returns A data frame with the following columns: Area Type, Area Code, Age Adjusted Incidence Rate, Lower 95% CI,
#' Upper 95% CI, CI Rank, Lower CI Rank, Upper CI Rank, Annual Average Count, Recent Trend,
#' Recent 5 Year Trend, Trend Lower 95% CI, Trend Upper 95% CI.
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Age Adjusted Incidence Rate, Lower 95% CI,
#' Upper 95% CI, CI Rank, Lower CI Rank, Upper CI Rank, Annual Average Count,
#' Recent Trend, Recent 5 Year Trend, Trend Lower 95% CI, Trend Upper 95% CI.
#'
#' @export
#'
Expand Down Expand Up @@ -100,13 +102,24 @@
#' }
incidence_cancer <- function(area, areatype, cancer, race, sex, age, stage, year) {
allstage_cancer <- c(
"all cancer sites", "breast (female in situ)", "childhood (ages <15, all sites)",
"childhood (ages <20, all sites)", "leukemia"
"all cancer sites",
"breast (female in situ)",
"childhood (ages <15, all sites)",
"childhood (ages <20, all sites)",
"leukemia"
)

female_cancer <- c("breast (female)", "breast (female in situ)", "ovary", "uterus (corpus & uterus, nos)")
female_cancer <- c(
"breast (female)",
"breast (female in situ)",
"ovary",
"uterus (corpus & uterus, nos)"
)

childhood_cancer <- c("childhood (ages <15, all sites)", "childhood (ages <20, all sites)")
childhood_cancer <- c(
"childhood (ages <15, all sites)",
"childhood (ages <20, all sites)"
)

if ((areatype == "county" || areatype == "hsa") && year == "latest single year (us by state)") {
cli_abort("For year latest single year (us by state), areatype must be state")
Expand Down Expand Up @@ -158,17 +171,45 @@ incidence_cancer <- function(area, areatype, cancer, race, sex, age, stage, year
resp <- process_incidence(resp)


areatype_map <- c("county" = "County", "hsa" = "Health Service Area", "state" = "State")
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]

if (stage == "all stages") {
resp %>%
setNames(c(areatype_title, areacode_title, "Age Adjusted Incidence Rate", "Lower 95% CI", "Upper 95% CI", "CI Rank", "Lower CI Rank", "Upper CI Rank", "Annual Average Count", "Recent Trend", "Recent 5 Year Trend", "Trend Lower 95% CI", "Trend Upper 95% CI"))
setNames(c(
areatype_title,
areacode_title,
"Age Adjusted Incidence Rate",
"Lower 95% CI",
"Upper 95% CI", "CI Rank",
"Lower CI Rank",
"Upper CI Rank",
"Annual Average Count",
"Recent Trend",
"Recent 5 Year Trend",
"Trend Lower 95% CI",
"Trend Upper 95% CI"
))
} else if (stage == "late stage (regional & distant)") {
resp %>%
setNames(c(areatype_title, areacode_title, "Age Adjusted Incidence Rate", "Lower 95% CI", "Upper 95% CI", "CI Rank", "Lower CI Rank", "Upper CI Rank", "Annual Average Count", "Percentage of Cases with Late Stage"))
setNames(c(
areatype_title,
areacode_title,
"Age Adjusted Incidence Rate",
"Lower 95% CI",
"Upper 95% CI",
"CI Rank",
"Lower CI Rank",
"Upper CI Rank",
"Annual Average Count",
"Percentage of Cases with Late Stage"
))
}
}
46 changes: 35 additions & 11 deletions R/mortality-cancer.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Access to Cancer Mortality Data
#'
#' This function returns a data frame about cancer mortality from State Cancer Profiles.
#' This function returns a data frame about cancer mortality
#' from State Cancer Profiles.
#'
#' @param area A state/territory abbreviation or USA.
#' @param areatype One of the following values:
Expand Down Expand Up @@ -52,10 +53,11 @@
#' - `"latest 5 year average"`
#' - `"latest single year (us by state)"`.
#'
#' @returns A data frame with the following columns: Area Type, Area Code, Met Healthy People Objective of ***?,
#' Age Adjusted Death Rate, Lower 95% CI Rate, Upper 95% CI Rate,
#' CI Rank, Lower CI Rank, Upper CI Rank, Annual Average Count,
#' Recent Trend, Recent 5 Year Trend, Lower 95% CI Trend, Upper 95% CI Trend.
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Met Healthy People Objective of ***?,
#' Age Adjusted Death Rate, Lower 95% CI Rate, Upper 95% CI Rate,
#' CI Rank, Lower CI Rank, Upper CI Rank, Annual Average Count,
#' Recent Trend, Recent 5 Year Trend, Lower 95% CI Trend, Upper 95% CI Trend.
#'
#' @export
#'
Expand Down Expand Up @@ -92,9 +94,16 @@
#' )
#' }
mortality_cancer <- function(area, areatype, cancer, race, sex, age, year) {
female_cancer <- c("breast (female)", "ovary", "uterus (corpus & uterus, nos)")
female_cancer <- c(
"breast (female)",
"ovary",
"uterus (corpus & uterus, nos)"
)

childhood_cancer <- c("childhood (ages <15, all sites)", "childhood (ages <20, all sites)")
childhood_cancer <- c(
"childhood (ages <15, all sites)",
"childhood (ages <20, all sites)"
)

if ((areatype == "county" || areatype == "hsa") && year == "latest single year (us by state)") {
cli_abort("For year latest single year (us by state), areatype must be state")
Expand Down Expand Up @@ -140,16 +149,31 @@ mortality_cancer <- function(area, areatype, cancer, race, sex, age, year) {

resp <- process_mortality(resp)

areatype_map <- c("county" = "County", "hsa" = "Health_Service_Area", "state" = "State")
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]

resp %>%
setNames(c(
areatype_title, areacode_title, "Met Healthy People Objective of ***?", "Age Adjusted Death Rate", "Lower 95% CI Rate", "Upper 95% CI Rate",
"CI Rank", "Lower CI Rank", "Upper CI Rank", "Annual Average Count", "Recent Trend",
"Recent 5 Year Trend", "Lower 95% CI Trend", "Upper 95% CI Trend"
areatype_title,
areacode_title,
"Met Healthy People Objective of ***?",
"Age Adjusted Death Rate",
"Lower 95% CI Rate",
"Upper 95% CI Rate",
"CI Rank",
"Lower CI Rank",
"Upper CI Rank",
"Annual Average Count",
"Recent Trend",
"Recent 5 Year Trend",
"Lower 95% CI Trend",
"Upper 95% CI Trend"
))
}
16 changes: 13 additions & 3 deletions R/risk-alcohol.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Access to Alcohol Screening and Risk Data
#'
#' This function returns a data frame about alcohol risks from State Cancer Profiles.
#' This function returns a data frame about alcohol risks
#' from State Cancer Profiles.
#'
#' @param alcohol The only permissible value is
#' `"binge drinking (4+ drinks on one occasion for women, 5+ drinks for one occasion for men), ages 21+"`.
Expand All @@ -16,7 +17,9 @@
#' - `"male"`
#' - `"female"`.
#'
#' @returns A data frame with the following columns: Area Type, Area Code, Percent, Lower 95% CI, Upper 95% CI, Number of Respondents.
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Percent, Lower 95% CI,
#' Upper 95% CI, Number of Respondents.
#'
#' @export
#'
Expand Down Expand Up @@ -50,5 +53,12 @@ risk_alcohol <- function(alcohol, race, sex) {
resp <- process_screening(resp)

resp %>%
setNames(c("State", "FIPS", "Percent", "Lower_95%_CI", "Upper_95%_CI", "Number_of_Respondents"))
setNames(c(
"State",
"FIPS",
"Percent",
"Lower_95%_CI",
"Upper_95%_CI",
"Number_of_Respondents"
))
}
17 changes: 15 additions & 2 deletions R/risk-colorectal-screening.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,22 @@ risk_colorectal_screening <- function(screening, race = NULL, sex = NULL, area =

if (screening %in% screening_type_1) {
resp %>%
setNames(c("State", "FIPS", "Percent", "Lower_95%_CI", "Upper_95%_CI", "Number_of_Respondents"))
setNames(c(
"State",
"FIPS",
"Percent",
"Lower_95%_CI",
"Upper_95%_CI",
"Number_of_Respondents"
))
} else if (screening %in% screening_type_2) {
resp %>%
setNames(c("County", "FIPS", "Model_Based_Percent (95%_Confidence_Interval)", "Lower_95%_CI", "Upper_95%_CI"))
setNames(c(
"County",
"FIPS",
"Model_Based_Percent (95%_Confidence_Interval)",
"Lower_95%_CI",
"Upper_95%_CI"
))
}
}
24 changes: 20 additions & 4 deletions R/risk-diet-exercise.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Access to Diet & Exercise Screening Data
#'
#' This function returns a data frame about diet and exercise risk from State Cancer Profiles.
#' This function returns a data frame about diet and exercise risk
#' from State Cancer Profiles.
#'
#' @param diet_exercise One of the following values:
#' - `"bmi is healthy, ages 20+"`
Expand All @@ -22,7 +23,9 @@
#' - `"male"`
#' - `"female"`.
#'
#' @returns A data frame with the following columns: Area Type, Area Code, Percent, Lower 95% CI, Upper 95% CI, Number of Respondents.
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Percent,
#' Lower 95% CI, Upper 95% CI, Number of Respondents.
#'
#' @export
#'
Expand Down Expand Up @@ -64,9 +67,22 @@ risk_diet_exercise <- function(diet_exercise, race, sex) {

if (diet_exercise %in% diet_exercise_type1) {
resp %>%
setNames(c("State", "FIPS", "Percent", "Lower_95%_CI", "Upper_95%_CI"))
setNames(c(
"State",
"FIPS",
"Percent",
"Lower_95%_CI",
"Upper_95%_CI"
))
} else {
resp %>%
setNames(c("State", "FIPS", "Percent", "Lower_95%_CI", "Upper_95%_CI", "Number_of_Respondents"))
setNames(c(
"State",
"FIPS",
"Percent",
"Lower_95%_CI",
"Upper_95%_CI",
"Number_of_Respondents"
))
}
}
33 changes: 29 additions & 4 deletions R/risk-smoking.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,38 @@ risk_smoking <- function(smoking, race = NULL, sex = NULL, datatype = NULL, area
if (smoking %in% smoking_group1) {
resp %>%
setNames(c("State", "FIPS", "Percent"))
} else if ((smoking %in% c(smoking_group2, smoking_group3, smoking_group4, smoking_group5, smoking_group6)) &&
} else if ((smoking %in% c(
smoking_group2,
smoking_group3,
smoking_group4,
smoking_group5,
smoking_group6
)) &&
(datatype == "direct estimates")) {
resp %>%
setNames(c("State", "FIPS", "Percent", "Lower_CI_95%", "Upper_CI_95%", "Number_of_Respondents"))
} else if ((smoking %in% c(smoking_group2, smoking_group3, smoking_group4, smoking_group5, smoking_group6) &&
setNames(c(
"State",
"FIPS",
"Percent",
"Lower_CI_95%",
"Upper_CI_95%",
"Number_of_Respondents"
))
} else if ((smoking %in% c(
smoking_group2,
smoking_group3,
smoking_group4,
smoking_group5,
smoking_group6
) &&
datatype == "county level modeled estimates")) {
resp %>%
setNames(c("County", "FIPS", "Percent", "Lower_CI_95%", "Upper_CI_95%"))
setNames(c(
"County",
"FIPS",
"Percent",
"Lower_CI_95%",
"Upper_CI_95%"
))
}
}
Loading

0 comments on commit 3b58631

Please sign in to comment.