From 3b58631555ee328e1df3d6a6f20c58665c655148 Mon Sep 17 00:00:00 2001 From: realbp Date: Thu, 7 Mar 2024 15:43:23 -0800 Subject: [PATCH] more linting and triple zeros --- R/demo-education.R | 6 +- R/demo-insurance.R | 18 ++-- R/incidence-cancer.R | 63 +++++++++++--- R/mortality-cancer.R | 46 +++++++--- R/risk-alcohol.R | 16 +++- R/risk-colorectal-screening.R | 17 +++- R/risk-diet-exercise.R | 24 +++++- R/risk-smoking.R | 33 +++++++- R/risk-vaccines.R | 26 +++++- R/risk-womens-health.R | 39 +++++++-- man/demo_insurance.Rd | 12 ++- man/incidence_cancer.Rd | 68 ++++++++------- man/mortality_cancer.Rd | 56 +++++++------ man/risk_alcohol.Rd | 19 +++-- man/risk_colorectal_screening.Rd | 24 ++++-- man/risk_diet_exercise.Rd | 23 +++-- man/risk_smoking.Rd | 34 ++++---- man/risk_vaccines.Rd | 21 +++-- man/risk_women_health.Rd | 34 +++++--- tests/testthat/test-demo-food-access.R | 28 +++++-- tests/testthat/test-demo-income.R | 28 ++++++- tests/testthat/test-demo-mobility.R | 12 ++- tests/testthat/test-demo-population.R | 83 ++++++++++++++++--- tests/testthat/test-demo-poverty.R | 27 +++++- tests/testthat/test-handle-age.R | 15 +++- tests/testthat/test-handle-cancer.R | 15 +++- tests/testthat/test-handle-food.R | 13 ++- tests/testthat/test-handle-income.R | 13 ++- tests/testthat/test-handle-population.R | 15 +++- tests/testthat/test-handle-risk-datatype.R | 13 ++- tests/testthat/test-handle-stage.R | 13 ++- tests/testthat/test-handle-year.R | 13 ++- tests/testthat/test-incidence-cancer.R | 30 +++++-- tests/testthat/test-mortality-cancer.R | 44 ++++++++-- .../testthat/test-risk-colorectal-screening.R | 33 ++++++-- tests/testthat/test-risk-diet-exercise.R | 6 +- tests/testthat/test-risk-smoking.R | 24 ++++-- tests/testthat/test-risk-womens-health.R | 6 +- vignettes/demographics-vignette.Rmd | 3 +- 39 files changed, 772 insertions(+), 241 deletions(-) diff --git a/R/demo-education.R b/R/demo-education.R index 0d866ae..f66d58f 100644 --- a/R/demo-education.R +++ b/R/demo-education.R @@ -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] diff --git a/R/demo-insurance.R b/R/demo-insurance.R index 2aa4e28..f1d43a7 100644 --- a/R/demo-insurance.R +++ b/R/demo-insurance.R @@ -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: @@ -24,7 +25,8 @@ #' - `"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"` @@ -32,7 +34,8 @@ #' - `"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"` @@ -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 #' @@ -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") diff --git a/R/incidence-cancer.R b/R/incidence-cancer.R index 3922b89..cdc9de8 100644 --- a/R/incidence-cancer.R +++ b/R/incidence-cancer.R @@ -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: @@ -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 #' @@ -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") @@ -158,7 +171,11 @@ 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") @@ -166,9 +183,33 @@ incidence_cancer <- function(area, areatype, cancer, race, sex, age, stage, year 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" + )) } } diff --git a/R/mortality-cancer.R b/R/mortality-cancer.R index 04dcdac..392de0b 100644 --- a/R/mortality-cancer.R +++ b/R/mortality-cancer.R @@ -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: @@ -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 #' @@ -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") @@ -140,7 +149,11 @@ 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") @@ -148,8 +161,19 @@ mortality_cancer <- function(area, areatype, cancer, race, sex, age, year) { 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" )) } diff --git a/R/risk-alcohol.R b/R/risk-alcohol.R index 684dbb2..ef01d4d 100644 --- a/R/risk-alcohol.R +++ b/R/risk-alcohol.R @@ -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+"`. @@ -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 #' @@ -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" + )) } diff --git a/R/risk-colorectal-screening.R b/R/risk-colorectal-screening.R index c824892..d455600 100644 --- a/R/risk-colorectal-screening.R +++ b/R/risk-colorectal-screening.R @@ -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" + )) } } diff --git a/R/risk-diet-exercise.R b/R/risk-diet-exercise.R index e4b33e8..05146f7 100644 --- a/R/risk-diet-exercise.R +++ b/R/risk-diet-exercise.R @@ -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+"` @@ -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 #' @@ -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" + )) } } diff --git a/R/risk-smoking.R b/R/risk-smoking.R index 8227cb4..c62334f 100644 --- a/R/risk-smoking.R +++ b/R/risk-smoking.R @@ -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%" + )) } } diff --git a/R/risk-vaccines.R b/R/risk-vaccines.R index 5ec87ac..e380d6c 100644 --- a/R/risk-vaccines.R +++ b/R/risk-vaccines.R @@ -1,6 +1,7 @@ #' Access to Vaccines Data #' -#' This function returns a data frame about vaccines risks from State Cancer Profiles. +#' This function returns a data frame about vaccines risks +#' from State Cancer Profiles. #' #' @param vaccine One of the following values: #' - `"percent with up to date hpv vaccination coverage, ages 13-15",` @@ -10,7 +11,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 #' @@ -53,9 +56,24 @@ risk_vaccines <- function(vaccine, sex) { if (vaccine %in% vaccine_type1) { resp %>% - setNames(c("State", "FIPS", "Met_Objective_of_80.0%?", "Percent", "Lower_95%_CI", "Upper_95%_CI", "Number_of_Respondents")) + setNames(c( + "State", + "FIPS", + "Met_Objective_of_80.0%?", + "Percent", + "Lower_95%_CI", + "Upper_95%_CI", + "Number_of_Respondents" + )) } 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" + )) } } diff --git a/R/risk-womens-health.R b/R/risk-womens-health.R index 9c5a255..61c2293 100644 --- a/R/risk-womens-health.R +++ b/R/risk-womens-health.R @@ -1,6 +1,7 @@ #' Access to Women's Health Data #' -#' This function returns a data frame about women's health risks from State Cancer Profiles. +#' This function returns a data frame about women's health risks +#' from State Cancer Profiles. #' #' @param women_health One of the following values: #' - `"mammogram in past 2 years, ages 50-74"` @@ -18,7 +19,8 @@ #' - `"county level modeled estimates"`. #' @param area A state/territory abbreviation or USA. #' -#' @returns A data frame with the following columns: Area Type, Area Code, Percent, People Unemployed, Rank. +#' @returns A data frame with the following columns: +#' Area Type, Area Code, Percent, People Unemployed, Rank. #' #' @export #' @@ -46,8 +48,11 @@ risk_women_health <- function(women_health, race, datatype = "direct estimates", req <- create_request("risk") risk_races <- c( - "all races (includes hispanic)", "white (non-hispanic)", "black (non-hispanic)", - "amer. indian / ak native (non-hispanic)", "asian / pacific islander (non-hispanic)", + "all races (includes hispanic)", + "white (non-hispanic)", + "black (non-hispanic)", + "amer. indian / ak native (non-hispanic)", + "asian / pacific islander (non-hispanic)", "hispanic (any race)" ) @@ -88,13 +93,33 @@ risk_women_health <- function(women_health, race, datatype = "direct estimates", if (datatype == "county level modeled estimates") { if (women_health == "pap smear in past 3 years, no hysterectomy, ages 21-65") { 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 { resp %>% - setNames(c("County", "FIPS", "Percent", "Lower_95%_CI", "Upper_95%_CI")) + setNames(c( + "County", + "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" + )) } } diff --git a/man/demo_insurance.Rd b/man/demo_insurance.Rd index f04addf..7cd5659 100644 --- a/man/demo_insurance.Rd +++ b/man/demo_insurance.Rd @@ -39,7 +39,8 @@ demo_insurance(area, areatype, insurance, sex, age, race = NULL) \item \code{"female"}. }} -\item{age}{If you specified \code{"both sexes"} for \code{sex} choose one of the following values: +\item{age}{If you specified \code{"both sexes"} for \code{sex} +choose one of the following values: \itemize{ \item \code{"under 19 years"} \item \code{"18 to 64 years"} @@ -49,7 +50,8 @@ demo_insurance(area, areatype, insurance, sex, age, race = NULL) \item \code{"under 65 years"}. } -Otherwise if you specified \code{"male"} or \code{"female"} for \code{sex}, choose one of the following values: +Otherwise if you specified \code{"male"} or \code{"female"} for \code{sex}, +choose one of the following values: \itemize{ \item \code{"18 to 64 years"} \item \code{"40 to 64 years"} @@ -68,10 +70,12 @@ Otherwise if you specified \code{"male"} or \code{"female"} for \code{sex}, choo }} } \value{ -A data frame with the following columns: Area Type, Area Code, Percent, People, Rank. +A data frame with the following columns: +Area Type, Area Code, Percent, People, Rank. } \description{ -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. } \examples{ \dontrun{ diff --git a/man/incidence_cancer.Rd b/man/incidence_cancer.Rd index a9ab1c0..395f891 100644 --- a/man/incidence_cancer.Rd +++ b/man/incidence_cancer.Rd @@ -84,40 +84,48 @@ incidence_cancer(area, areatype, cancer, race, sex, age, stage, year) }} } \value{ -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. +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. } \description{ -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. } \examples{ \dontrun{ -incidence_cancer(area = "wa", - areatype = "county", - cancer = "all cancer sites", - race = "black (non-hispanic)", - sex = "both sexes", - age = "ages 65+", - stage = "all stages", - year = "latest 5 year average") - -incidence_cancer(area = "usa", - areatype = "state", - cancer = "lung & bronchus", - race = "all races (includes hispanic)", - sex = "males", - age = "ages 50+", - stage = "late stage (regional & distant)", - year = "latest single year (us by state)") - -incidence_cancer(area = "wa", - areatype = "hsa", - cancer = "ovary", - race = "all races (includes hispanic)", - sex = "females", - age = "ages 50+", - stage = "late stage (regional & distant)", - year = "latest 5 year average") +incidence_cancer( + area = "wa", + areatype = "county", + cancer = "all cancer sites", + race = "black (non-hispanic)", + sex = "both sexes", + age = "ages 65+", + stage = "all stages", + year = "latest 5 year average" +) + +incidence_cancer( + area = "usa", + areatype = "state", + cancer = "lung & bronchus", + race = "all races (includes hispanic)", + sex = "males", + age = "ages 50+", + stage = "late stage (regional & distant)", + year = "latest single year (us by state)" +) + +incidence_cancer( + area = "wa", + areatype = "hsa", + cancer = "ovary", + race = "all races (includes hispanic)", + sex = "females", + age = "ages 50+", + stage = "late stage (regional & distant)", + year = "latest 5 year average" +) } } diff --git a/man/mortality_cancer.Rd b/man/mortality_cancer.Rd index 956b2d9..98d889b 100644 --- a/man/mortality_cancer.Rd +++ b/man/mortality_cancer.Rd @@ -74,38 +74,46 @@ mortality_cancer(area, areatype, cancer, race, sex, age, year) }} } \value{ -A data frame with the following columns: Area Type, Area Code, Met Healthy People Objective of ***?, +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. } \description{ -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. } \examples{ \dontrun{ -mortality_cancer(area = "wa", - areatype = "county", - cancer = "all cancer sites", - race = "black (non-hispanic)", - sex = "both sexes", - age = "ages 65+", - year = "latest 5 year average") +mortality_cancer( + area = "wa", + areatype = "county", + cancer = "all cancer sites", + race = "black (non-hispanic)", + sex = "both sexes", + age = "ages 65+", + year = "latest 5 year average" +) -mortality_cancer(area = "usa", - areatype = "state", - cancer = "prostate", - race = "all races (includes hispanic)", - sex = "males", - age = "ages 50+", - year = "latest single year (us by state)") - -mortality_cancer(area = "wa", - areatype = "hsa", - cancer = "ovary", - race = "all races (includes hispanic)", - sex = "females", - age = "ages 50+", - year = "latest 5 year average") +mortality_cancer( + area = "usa", + areatype = "state", + cancer = "prostate", + race = "all races (includes hispanic)", + sex = "males", + age = "ages 50+", + year = "latest single year (us by state)" +) + +mortality_cancer( + area = "wa", + areatype = "hsa", + cancer = "ovary", + race = "all races (includes hispanic)", + sex = "females", + age = "ages 50+", + year = "latest 5 year average" +) } } diff --git a/man/risk_alcohol.Rd b/man/risk_alcohol.Rd index ca55be7..86092f5 100644 --- a/man/risk_alcohol.Rd +++ b/man/risk_alcohol.Rd @@ -28,16 +28,23 @@ risk_alcohol(alcohol, race, sex) }} } \value{ -A data frame with the following columns: Area Type, Area Code, Percent, Lower 95\% CI, Upper 95\% CI, Number of Respondents. +A data frame with the following columns: +Area Type, Area Code, Percent, Lower 95\% CI, +Upper 95\% CI, Number of Respondents. } \description{ -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. } \examples{ \dontrun{ -risk_alcohol(alcohol = paste("binge drinking (4+ drinks on one occasion for women,", - "5+ drinks for one occasion for men), ages 21+"), - race = "all races (includes hispanic)", - sex = "both sexes") +risk_alcohol( + alcohol = paste( + "binge drinking (4+ drinks on one occasion for women,", + "5+ drinks for one occasion for men), ages 21+" + ), + race = "all races (includes hispanic)", + sex = "both sexes" +) } } diff --git a/man/risk_colorectal_screening.Rd b/man/risk_colorectal_screening.Rd index 2dc111d..4165e27 100644 --- a/man/risk_colorectal_screening.Rd +++ b/man/risk_colorectal_screening.Rd @@ -45,14 +45,20 @@ colorectal screening from State Cancer Profiles. } \examples{ \dontrun{ -risk_colorectal_screening(screening = "home blood stool test in the past year, ages 45-75", - race = "all races (includes hispanic)", - sex = "both sexes") - -risk_colorectal_screening(screening = "ever had fobt, ages 50-75", - area="usa") -risk_colorectal_screening(screening = "received at least one recommended crc test, ages 45-75", - race = "all races (includes hispanic)", - sex = "both sexes") +risk_colorectal_screening( + screening = "home blood stool test in the past year, ages 45-75", + race = "all races (includes hispanic)", + sex = "both sexes" +) + +risk_colorectal_screening( + screening = "ever had fobt, ages 50-75", + area = "usa" +) +risk_colorectal_screening( + screening = "received at least one recommended crc test, ages 45-75", + race = "all races (includes hispanic)", + sex = "both sexes" +) } } diff --git a/man/risk_diet_exercise.Rd b/man/risk_diet_exercise.Rd index 887e50d..208421c 100644 --- a/man/risk_diet_exercise.Rd +++ b/man/risk_diet_exercise.Rd @@ -36,18 +36,25 @@ risk_diet_exercise(diet_exercise, race, sex) }} } \value{ -A data frame with the following columns: Area Type, Area Code, Percent, Lower 95\% CI, Upper 95\% CI, Number of Respondents. +A data frame with the following columns: +Area Type, Area Code, Percent, +Lower 95\% CI, Upper 95\% CI, Number of Respondents. } \description{ -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. } \examples{ \dontrun{ -risk_diet_exercise(diet_exercise = "bmi is healthy, ages 20+", - race = "all races (includes hispanic)", - sex = "both sexes") -risk_diet_exercise(diet_exercise = "bmi is obese, high school survey", - race = "all races (includes hispanic)", - sex = "males") +risk_diet_exercise( + diet_exercise = "bmi is healthy, ages 20+", + race = "all races (includes hispanic)", + sex = "both sexes" +) +risk_diet_exercise( + diet_exercise = "bmi is obese, high school survey", + race = "all races (includes hispanic)", + sex = "males" +) } } diff --git a/man/risk_smoking.Rd b/man/risk_smoking.Rd index dfeea37..1da66a9 100644 --- a/man/risk_smoking.Rd +++ b/man/risk_smoking.Rd @@ -70,19 +70,25 @@ very specific arguments for each smoking type. \dontrun{ risk_smoking(smoking = "smoking laws (any)") -risk_smoking(smoking = "smokers (stopped for 1 day or longer)", - sex = "both sexes", - datatype = "county level modeled estimates", - area = "wa") - -risk_smoking(smoking = "smoking not allowed at work (current smokers)", - sex = "both sexes", - datatype = "direct estimates") - -risk_smoking(smoking = "smokers (current); ages 18+", - race = "all races (includes hispanic)", - sex = "both sexes", - datatype = "county level modeled estimates", - area="wa") +risk_smoking( + smoking = "smokers (stopped for 1 day or longer)", + sex = "both sexes", + datatype = "county level modeled estimates", + area = "wa" +) + +risk_smoking( + smoking = "smoking not allowed at work (current smokers)", + sex = "both sexes", + datatype = "direct estimates" +) + +risk_smoking( + smoking = "smokers (current); ages 18+", + race = "all races (includes hispanic)", + sex = "both sexes", + datatype = "county level modeled estimates", + area = "wa" +) } } diff --git a/man/risk_vaccines.Rd b/man/risk_vaccines.Rd index 2c25820..a78c7f1 100644 --- a/man/risk_vaccines.Rd +++ b/man/risk_vaccines.Rd @@ -21,17 +21,24 @@ risk_vaccines(vaccine, sex) }} } \value{ -A data frame with the following columns: Area Type, Area Code, Percent, Lower 95\% CI, Upper 95\% CI, Number of Respondents. +A data frame with the following columns: +Area Type, Area Code, Percent, +Lower 95\% CI, Upper 95\% CI, Number of Respondents. } \description{ -This function returns a data frame about vaccines risks from State Cancer Profiles. +This function returns a data frame about vaccines risks +from State Cancer Profiles. } \examples{ \dontrun{ -risk_vaccines(vaccine = "percent with up to date hpv vaccination coverage, ages 13-15", - sex = "both sexes") - -risk_vaccines(vaccine = "percent with up to date hpv vaccination coverage, ages 13-17", - sex = "females") +risk_vaccines( + vaccine = "percent with up to date hpv vaccination coverage, ages 13-15", + sex = "both sexes" +) + +risk_vaccines( + vaccine = "percent with up to date hpv vaccination coverage, ages 13-17", + sex = "females" +) } } diff --git a/man/risk_women_health.Rd b/man/risk_women_health.Rd index e5f7eed..4ccd2cd 100644 --- a/man/risk_women_health.Rd +++ b/man/risk_women_health.Rd @@ -38,23 +38,31 @@ risk_women_health( \item{area}{A state/territory abbreviation or USA.} } \value{ -A data frame with the following columns: Area Type, Area Code, Percent, People Unemployed, Rank. +A data frame with the following columns: +Area Type, Area Code, Percent, People Unemployed, Rank. } \description{ -This function returns a data frame about women's health risks from State Cancer Profiles. +This function returns a data frame about women's health risks +from State Cancer Profiles. } \examples{ \dontrun{ -risk_women_health(women_health = "mammogram in past 2 years, ages 50-74", - race = "all races (includes hispanic)", - datatype = "direct estimates") - -risk_women_health(women_health = "pap smear in past 3 years, no hysterectomy, ages 21-65", - race = "all races (includes hispanic)", - datatype = "county level modeled estimates", - area = "wa") - -risk_women_health(women_health = "pap smear in past 3 years, no hysteroetomy, ages 21-65", - race = "black (non-hispanic)") +risk_women_health( + women_health = "mammogram in past 2 years, ages 50-74", + race = "all races (includes hispanic)", + datatype = "direct estimates" +) + +risk_women_health( + women_health = "pap smear in past 3 years, no hysterectomy, ages 21-65", + race = "all races (includes hispanic)", + datatype = "county level modeled estimates", + area = "wa" +) + +risk_women_health( + women_health = "pap smear in past 3 years, no hysteroetomy, ages 21-65", + race = "black (non-hispanic)" +) } } diff --git a/tests/testthat/test-demo-food-access.R b/tests/testthat/test-demo-food-access.R index 2f7fb93..e333c0b 100644 --- a/tests/testthat/test-demo-food-access.R +++ b/tests/testthat/test-demo-food-access.R @@ -19,20 +19,33 @@ test_that("Output data type is correct", { # Ensures that variables are present and working on SCP test_that("demo-food returns non-empty data frame", { skip_on_cran() - food_test_1 <- demo_food("wa", "county", "food insecurity", "all races (includes hispanic)") + food_test_1 <- demo_food( + "wa", + "county", + "food insecurity", + "all races (includes hispanic)" + ) expect_true(!is.null(food_test_1)) expect_true(is.data.frame(food_test_1)) - food_test_2 <- demo_food("usa", "state", "limited access to healthy food") + food_test_2 <- demo_food( + "usa", + "state", + "limited access to healthy food" + ) expect_true(!is.null(food_test_2)) expect_true(is.data.frame(food_test_2)) - food_test_3 <- demo_food("pr", "county", "food insecurity", "all races (includes hispanic)") + food_test_3 <- demo_food( + "pr", + "county", + "food insecurity", + "all races (includes hispanic)" + ) expect_true(!is.null(food_test_3)) expect_true(is.data.frame(food_test_3)) }) -# sometimes functions will output different nuber of columns depending on variables... # demo-food must have 5 columns test_that("demo-food has correct number of columns", { skip_on_cran() @@ -48,7 +61,12 @@ test_that("demo-food has correct number of columns", { test_that("demo-food handles invalid education parameters", { skip_on_cran() expect_error( - demo_food("wa", "county", "limited access to healthy food", "all races (includes hispanic)"), + demo_food( + "wa", + "county", + "limited access to healthy food", + "all races (includes hispanic)" + ), "For limited access to healthy food, Race must be NULL" ) expect_error( diff --git a/tests/testthat/test-demo-income.R b/tests/testthat/test-demo-income.R index 091d829..118ff9d 100644 --- a/tests/testthat/test-demo-income.R +++ b/tests/testthat/test-demo-income.R @@ -5,7 +5,12 @@ # tests class and typeof output test_that("Output data type is correct", { skip_on_cran() - output <- demo_income("wa", "county", "median family income", "all races (includes hispanic)") + output <- demo_income( + "wa", + "county", + "median family income", + "all races (includes hispanic)" + ) expect_true(inherits(output, "data.frame")) }) @@ -13,17 +18,32 @@ test_that("Output data type is correct", { # Ensures that variables are present and working on SCP test_that("demo-income returns non-empty data frame", { skip_on_cran() - income1 <- demo_income("wa", "county", "median family income", "all races (includes hispanic)") + income1 <- demo_income( + "wa", + "county", + "median family income", + "all races (includes hispanic)" + ) expect_true(is.data.frame(income1)) - income2 <- demo_income("usa", "state", "median household income", "all races (includes hispanic)") + income2 <- demo_income( + "usa", + "state", + "median household income", + "all races (includes hispanic)" + ) expect_true(is.data.frame(income2)) }) # demo-income must have 5 columns test_that("demo-income has correct number of columns", { skip_on_cran() - df <- demo_income("usa", "state", "median household income", "all races (includes hispanic)") + df <- demo_income( + "usa", + "state", + "median household income", + "all races (includes hispanic)" + ) expected_columns <- 4 expect_equal(ncol(df), expected_columns) }) diff --git a/tests/testthat/test-demo-mobility.R b/tests/testthat/test-demo-mobility.R index f29880d..41f5488 100644 --- a/tests/testthat/test-demo-mobility.R +++ b/tests/testthat/test-demo-mobility.R @@ -5,7 +5,11 @@ # tests class and typeof output test_that("Output data type is correct", { skip_on_cran() - output <- demo_mobility("wa", "county", "moved, different county, same state (in past year)") + output <- demo_mobility( + "wa", + "county", + "moved, different county, same state (in past year)" + ) expect_true(inherits(output, "data.frame")) }) @@ -29,7 +33,11 @@ for (option in mobility_options) { # demo-mobility must have 5 columns test_that("demo-mobility has correct number of columns", { skip_on_cran() - df <- demo_mobility("wa", "county", "moved, different county, same state (in past year)") + df <- demo_mobility( + "wa", + "county", + "moved, different county, same state (in past year)" + ) expected_columns <- 5 expect_equal(ncol(df), expected_columns) }) diff --git a/tests/testthat/test-demo-population.R b/tests/testthat/test-demo-population.R index 6ee966b..26673fb 100644 --- a/tests/testthat/test-demo-population.R +++ b/tests/testthat/test-demo-population.R @@ -5,22 +5,67 @@ # tests class and typeof output test_that("Output data type is correct", { skip_on_cran() - output <- demo_population("WA", "county", "asian/pacific islander", sex = "females") + output <- demo_population("WA", + "county", + "asian/pacific islander", + sex = "females" + ) expect_true(inherits(output, "data.frame")) }) # Ensures that variables are present and working on SCP population_options <- list( - age1 = demo_population("wa", "county", "age under 18", "all races (includes hispanic)", "both sexes"), - age2 = demo_population("wa", "county", "ages 60 and over", "all races (includes hispanic)", "both sexes"), - age3 = demo_population("wa", "county", "age 18-39", sex = "both sexes"), - age4 = demo_population("wa", "county", "age 40-64", sex = "both sexes"), - age5 = demo_population("wa", "county", "ages 40 and over"), - age6 = demo_population("wa", "county", "ages 50 and over"), - race1 = demo_population("wa", "county", "foreign born", "all races (includes hispanic)", "both sexes"), - sex1 = demo_population("wa", "county", "males", race = "all races (includes hispanic)"), - sex2 = demo_population("wa", "county", "females", race = "all races (includes hispanic)") + age1 = demo_population( + "wa", + "county", + "age under 18", + "all races (includes hispanic)", + "both sexes" + ), + age2 = demo_population( + "wa", + "county", + "ages 60 and over", + "all races (includes hispanic)", + "both sexes" + ), + age3 = demo_population("wa", + "county", + "age 18-39", + sex = "both sexes" + ), + age4 = demo_population("wa", + "county", + "age 40-64", + sex = "both sexes" + ), + age5 = demo_population( + "wa", + "county", + "ages 40 and over" + ), + age6 = demo_population( + "wa", + "county", + "ages 50 and over" + ), + race1 = demo_population( + "wa", + "county", + "foreign born", + "all races (includes hispanic)", "both sexes" + ), + sex1 = demo_population("wa", + "county", + "males", + race = "all races (includes hispanic)" + ), + sex2 = demo_population("wa", + "county", + "females", + race = "all races (includes hispanic)" + ) ) for (option_name in names(population_options)) { @@ -39,14 +84,22 @@ race_options <- c( for (option in race_options) { test_that("demo-population returns non-empty data frame", { skip_on_cran() - expect_true(is.data.frame(demo_population("wa", "county", option, sex = "both sexes"))) + expect_true(is.data.frame(demo_population("wa", + "county", + option, + sex = "both sexes" + ))) }) } # demo-population must have 5 columns test_that("demo-population has correct number of columns", { skip_on_cran() - df <- demo_population("WA", "county", "asian/pacific islander", sex = "females") + df <- demo_population("WA", + "county", + "asian/pacific islander", + sex = "females" + ) expected_columns <- 5 expect_equal(ncol(df), expected_columns) }) @@ -55,7 +108,11 @@ test_that("demo-population has correct number of columns", { test_that("demo-population handles invalid population parameters", { skip_on_cran() expect_error( - demo_population("wa", "county", "ages 40 and over", race = "all races includes hispanic"), + demo_population("wa", + "county", + "ages 40 and over", + race = "all races includes hispanic" + ), "ages 40 and over and ages 50 and over, Race and Sex must be NULL" ) expect_error( diff --git a/tests/testthat/test-demo-poverty.R b/tests/testthat/test-demo-poverty.R index 91d84c8..a1374ad 100644 --- a/tests/testthat/test-demo-poverty.R +++ b/tests/testthat/test-demo-poverty.R @@ -12,10 +12,29 @@ test_that("Output data type is correct", { # Ensures that variables are present and working on SCP poverty_options <- list( - pov1 = demo_poverty("wa", "county", "persistent poverty"), - pov2 = demo_poverty("wa", "county", "families below poverty", "black"), - pov3 = demo_poverty("wa", "county", "persons below poverty", "black", "both sexes"), - pov4 = demo_poverty("wa", "county", "persons < 150% of poverty") + pov1 = demo_poverty( + "wa", + "county", + "persistent poverty" + ), + pov2 = demo_poverty( + "wa", + "county", + "families below poverty", + "black" + ), + pov3 = demo_poverty( + "wa", + "county", + "persons below poverty", + "black", + "both sexes" + ), + pov4 = demo_poverty( + "wa", + "county", + "persons < 150% of poverty" + ) ) for (option_name in names(poverty_options)) { diff --git a/tests/testthat/test-handle-age.R b/tests/testthat/test-handle-age.R index 8655174..264f840 100644 --- a/tests/testthat/test-handle-age.R +++ b/tests/testthat/test-handle-age.R @@ -2,8 +2,19 @@ #' #' This testthat file tests the handle-age function test_that("handle age correctly maps age", { - result <- sapply(c("under 19 years", "under 65 years", "all ages"), handle_age) - expected <- c(`under 19 years` = "175", `under 65 years` = "006", `all ages` = "001") + result <- sapply( + c( + "under 19 years", + "under 65 years", + "all ages" + ), + handle_age + ) + expected <- c( + `under 19 years` = "175", + `under 65 years` = "006", + `all ages` = "001" + ) expect_equal(result, expected) }) diff --git a/tests/testthat/test-handle-cancer.R b/tests/testthat/test-handle-cancer.R index c6c9adf..fc7de38 100644 --- a/tests/testthat/test-handle-cancer.R +++ b/tests/testthat/test-handle-cancer.R @@ -2,8 +2,19 @@ #' #' This testthat file tests the handle-cancer function test_that("handle cancer correctly maps cancer", { - result <- sapply(c("all cancer sites", "breast (female)", "prostate"), handle_cancer) - expected <- c(`all cancer sites` = "001", `breast (female)` = "055", `prostate` = "066") + result <- sapply( + c( + "all cancer sites", + "breast (female)", + "prostate" + ), + handle_cancer + ) + expected <- c( + `all cancer sites` = "001", + `breast (female)` = "055", + `prostate` = "066" + ) expect_equal(result, expected) }) diff --git a/tests/testthat/test-handle-food.R b/tests/testthat/test-handle-food.R index 8ebde82..524bb72 100644 --- a/tests/testthat/test-handle-food.R +++ b/tests/testthat/test-handle-food.R @@ -2,8 +2,17 @@ #' #' This testthat file tests the handle-food function test_that("handle food correctly maps food", { - result <- sapply(c("food insecurity", "limited access to healthy food"), handle_food) - expected <- c(`food insecurity` = "03003", `limited access to healthy food` = "03004") + result <- sapply( + c( + "food insecurity", + "limited access to healthy food" + ), + handle_food + ) + expected <- c( + `food insecurity` = "03003", + `limited access to healthy food` = "03004" + ) expect_equal(result, expected) }) diff --git a/tests/testthat/test-handle-income.R b/tests/testthat/test-handle-income.R index 50cad40..f35c0d9 100644 --- a/tests/testthat/test-handle-income.R +++ b/tests/testthat/test-handle-income.R @@ -2,8 +2,17 @@ #' #' This testthat file tests the handle-income function test_that("handle income correctly maps income", { - result <- sapply(c("median family income", "median household income"), handle_income) - expected <- c(`median family income` = "00010", `median household income` = "00011") + result <- sapply( + c( + "median family income", + "median household income" + ), + handle_income + ) + expected <- c( + `median family income` = "00010", + `median household income` = "00011" + ) expect_equal(result, expected) }) diff --git a/tests/testthat/test-handle-population.R b/tests/testthat/test-handle-population.R index 74f3c15..c67d19a 100644 --- a/tests/testthat/test-handle-population.R +++ b/tests/testthat/test-handle-population.R @@ -2,8 +2,19 @@ #' #' This testthat file tests the handle-population function test_that("handle population correctly maps population", { - result <- sapply(c("age under 18", "foreign born", "males"), handle_population) - expected <- c(`age under 18` = "00002", `foreign born` = "00014", `males` = "00104") + result <- sapply( + c( + "age under 18", + "foreign born", + "males" + ), + handle_population + ) + expected <- c( + `age under 18` = "00002", + `foreign born` = "00014", + `males` = "00104" + ) expect_equal(result, expected) }) diff --git a/tests/testthat/test-handle-risk-datatype.R b/tests/testthat/test-handle-risk-datatype.R index 87e3c39..5b93e3e 100644 --- a/tests/testthat/test-handle-risk-datatype.R +++ b/tests/testthat/test-handle-risk-datatype.R @@ -2,8 +2,17 @@ #' #' This testthat file tests the handle-datatype function test_that("handle datatype correctly maps datatype", { - result <- sapply(c("direct estimates", "county level modeled estimates"), handle_datatype) - expected <- c(`direct estimates` = "0", `county level modeled estimates` = "1") + result <- sapply( + c( + "direct estimates", + "county level modeled estimates" + ), + handle_datatype + ) + expected <- c( + `direct estimates` = "0", + `county level modeled estimates` = "1" + ) expect_equal(result, expected) }) diff --git a/tests/testthat/test-handle-stage.R b/tests/testthat/test-handle-stage.R index 719ae59..40954e0 100644 --- a/tests/testthat/test-handle-stage.R +++ b/tests/testthat/test-handle-stage.R @@ -2,8 +2,17 @@ #' #' This testthat file tests the handle-stage function test_that("handle stage correctly maps stage", { - result <- sapply(c("all stages", "late stage (regional & distant)"), handle_stage) - expected <- c(`all stages` = "999", `late stage (regional & distant)` = "211") + result <- sapply( + c( + "all stages", + "late stage (regional & distant)" + ), + handle_stage + ) + expected <- c( + `all stages` = "999", + `late stage (regional & distant)` = "211" + ) expect_equal(result, expected) }) diff --git a/tests/testthat/test-handle-year.R b/tests/testthat/test-handle-year.R index 6ec946a..3689736 100644 --- a/tests/testthat/test-handle-year.R +++ b/tests/testthat/test-handle-year.R @@ -2,8 +2,17 @@ #' #' This testthat file tests the handle-year function test_that("handle year correctly maps year", { - result <- sapply(c("latest 5 year average", "latest single year (us by state)"), handle_year) - expected <- c(`latest 5 year average` = "0", `latest single year (us by state)` = "1") + result <- sapply( + c( + "latest 5 year average", + "latest single year (us by state)" + ), + handle_year + ) + expected <- c( + `latest 5 year average` = "0", + `latest single year (us by state)` = "1" + ) expect_equal(result, expected) }) diff --git a/tests/testthat/test-incidence-cancer.R b/tests/testthat/test-incidence-cancer.R index f6a75b4..4ee1971 100644 --- a/tests/testthat/test-incidence-cancer.R +++ b/tests/testthat/test-incidence-cancer.R @@ -52,16 +52,34 @@ for (option in female_cancer_options) { childhood_male_cancer_options <- list( childhood15 = incidence_cancer( - "ca", "hsa", "childhood (ages <20, all sites)", "all races (includes hispanic)", - "males", "ages <20", "all stages", "latest 5 year average" + "ca", + "hsa", + "childhood (ages <20, all sites)", + "all races (includes hispanic)", + "males", + "ages <20", + "all stages", + "latest 5 year average" ), childhood20 = incidence_cancer( - "ca", "hsa", "childhood (ages <20, all sites)", "all races (includes hispanic)", - "males", "ages <20", "all stages", "latest 5 year average" + "ca", + "hsa", + "childhood (ages <20, all sites)", + "all races (includes hispanic)", + "males", + "ages <20", + "all stages", + "latest 5 year average" ), prostate = incidence_cancer( - "usa", "state", "prostate", "all races (includes hispanic)", - "males", "ages 50+", "all stages", "latest 5 year average" + "usa", + "state", + "prostate", + "all races (includes hispanic)", + "males", + "ages 50+", + "all stages", + "latest 5 year average" ) ) diff --git a/tests/testthat/test-mortality-cancer.R b/tests/testthat/test-mortality-cancer.R index 3fb77d0..df1a9bd 100644 --- a/tests/testthat/test-mortality-cancer.R +++ b/tests/testthat/test-mortality-cancer.R @@ -32,12 +32,25 @@ for (option in cancer_options) { }) } -female_cancer_options <- c("breast (female)", "cervix", "ovary", "uterus (corpus & uterus, nos)") +female_cancer_options <- c( + "breast (female)", + "cervix", + "ovary", + "uterus (corpus & uterus, nos)" +) for (option in female_cancer_options) { test_that("mortality female cancer returns non-empty data frame", { skip_on_cran() - result <- mortality_cancer("wa", "county", option, "all races (includes hispanic)", "females", "ages 50+", "latest 5 year average") + result <- mortality_cancer( + "wa", + "county", + option, + "all races (includes hispanic)", + "females", + "ages 50+", + "latest 5 year average" + ) expect_true(is.data.frame(result)) }) @@ -45,16 +58,31 @@ for (option in female_cancer_options) { childhood_male_cancer_options <- list( childhood15 = mortality_cancer( - "ca", "hsa", "childhood (ages <20, all sites)", "all races (includes hispanic)", - "males", "ages <20", "latest 5 year average" + "ca", + "hsa", + "childhood (ages <20, all sites)", + "all races (includes hispanic)", + "males", + "ages <20", + "latest 5 year average" ), childhood20 = mortality_cancer( - "ca", "hsa", "childhood (ages <20, all sites)", "all races (includes hispanic)", - "males", "ages <20", "latest 5 year average" + "ca", + "hsa", + "childhood (ages <20, all sites)", + "all races (includes hispanic)", + "males", + "ages <20", + "latest 5 year average" ), prostate = mortality_cancer( - "usa", "state", "prostate", "all races (includes hispanic)", - "males", "ages 50+", "latest 5 year average" + "usa", + "state", + "prostate", + "all races (includes hispanic)", + "males", + "ages 50+", + "latest 5 year average" ) ) diff --git a/tests/testthat/test-risk-colorectal-screening.R b/tests/testthat/test-risk-colorectal-screening.R index 894a925..2919815 100644 --- a/tests/testthat/test-risk-colorectal-screening.R +++ b/tests/testthat/test-risk-colorectal-screening.R @@ -5,16 +5,28 @@ # tests class and typeof output test_that("Output data type is correct", { skip_on_cran() - output <- risk_colorectal_screening("ever had fobt, ages 50-75", area = "wa") + output <- risk_colorectal_screening( + "ever had fobt, ages 50-75", + area = "wa" + ) expect_true(inherits(output, "data.frame")) }) # Ensures that variables are present and working on SCP screening_options <- list( - screening1 = risk_colorectal_screening("ever had fobt, ages 50-75", area = "wa"), - screening2 = risk_colorectal_screening("guidance sufficient crc, ages 50-75", area = "wa"), - screening3 = risk_colorectal_screening("had colonoscopy in past 10 years, ages 50-75", area = "wa"), + screening1 = risk_colorectal_screening( + "ever had fobt, ages 50-75", + area = "wa" + ), + screening2 = risk_colorectal_screening( + "guidance sufficient crc, ages 50-75", + area = "wa" + ), + screening3 = risk_colorectal_screening( + "had colonoscopy in past 10 years, ages 50-75", + area = "wa" + ), screening4 = risk_colorectal_screening( "home blood stool test in the past year, ages 45-75", "all races (includes hispanic)", "both sexes" @@ -48,11 +60,18 @@ test_that("risk-colorectal-screening has correct number of columns", { }) # test error handling -test_that("risk-colorectal-screening handles invalid colorectal_screening parameters", { +test_that("risk-colorectal-screening handles + invalid colorectal_screening parameters", { skip_on_cran() expect_error( - risk_colorectal_screening("ever had fobt, ages 50-75", race = "all races (includes hispanic)"), - "for this screening type, area must NOT be NULL and Race and Sex must be NULL" + risk_colorectal_screening( + "ever had fobt, ages 50-75", + race = "all races (includes hispanic)" + ), + paste( + "for this screening type,", + "area must NOT be NULL and Race and Sex must be NULL" + ) ) expect_error( risk_colorectal_screening( diff --git a/tests/testthat/test-risk-diet-exercise.R b/tests/testthat/test-risk-diet-exercise.R index d141781..813ffde 100644 --- a/tests/testthat/test-risk-diet-exercise.R +++ b/tests/testthat/test-risk-diet-exercise.R @@ -24,7 +24,11 @@ diet_exercise_options <- c( for (option in diet_exercise_options) { test_that("risk_diet_exercise returns non-empty data frame", { skip_on_cran() - result <- risk_diet_exercise(option, "all races (includes hispanic)", "both sexes") + result <- risk_diet_exercise( + option, + "all races (includes hispanic)", + "both sexes" + ) expect_true(is.data.frame(result)) }) } diff --git a/tests/testthat/test-risk-smoking.R b/tests/testthat/test-risk-smoking.R index e93114d..7f00c5b 100644 --- a/tests/testthat/test-risk-smoking.R +++ b/tests/testthat/test-risk-smoking.R @@ -39,7 +39,10 @@ smoking_group2_options <- c( for (option in smoking_group2_options) { test_that("smoking group2 returns non-empty data frame", { skip_on_cran() - result <- risk_smoking(option, sex = "both sexes", datatype = "direct estimates") + result <- risk_smoking(option, + sex = "both sexes", + datatype = "direct estimates" + ) expect_true(is.data.frame(result)) }) } @@ -55,7 +58,10 @@ smoking_group3_options <- c( for (option in smoking_group3_options) { test_that("smoking group3 returns non-empty data frame", { skip_on_cran() - result <- risk_smoking(option, sex = "both sexes", datatype = "direct estimates") + result <- risk_smoking(option, + sex = "both sexes", + datatype = "direct estimates" + ) expect_true(is.data.frame(result)) }) } @@ -137,7 +143,8 @@ test_that("risk-smoking handles invalid smoking parameters", { sex = "both sexes", datatype = "county level modeled estimates" ), - "For county level modeled estimates on this smoking type, area must NOT be null" + paste("For county level modeled estimates on this smoking type,", + "area must NOT be null") ) expect_error( risk_smoking("smoking not allowed at work (current smokers)", @@ -151,11 +158,16 @@ test_that("risk-smoking handles invalid smoking parameters", { sex = "both sexes", datatype = "county level modeled estimates" ), - "For this smoking type, Sex, Datatype, and Area must not be NULL AND Race must be NULL" + paste("For this smoking type, Sex, Datatype,", + "and Area must not be NULL AND Race must be NULL") ) expect_error( - risk_smoking("smokers (ever); ages 18+", race = "hispanic (any race)", sex = "both sexes"), - "For this smoking type, Race, Sex, and Datatype must not be NULL AND Datatype and Area must be NULL" + risk_smoking("smokers (ever); ages 18+", + race = "hispanic (any race)", + sex = "both sexes" + ), + paste("For this smoking type, Race, Sex,", + "and Datatype must not be NULL AND Datatype and Area must be NULL") ) expect_error( risk_smoking("smokers (current); ages 18+", diff --git a/tests/testthat/test-risk-womens-health.R b/tests/testthat/test-risk-womens-health.R index a46aedc..a3eab3a 100644 --- a/tests/testthat/test-risk-womens-health.R +++ b/tests/testthat/test-risk-womens-health.R @@ -23,7 +23,11 @@ womens_health_options <- c( for (option in womens_health_options) { test_that("risk_womens_health returns non-empty data frame", { skip_on_cran() - result <- risk_women_health(option, "all races (includes hispanic)", "direct estimates") + result <- risk_women_health( + option, + "all races (includes hispanic)", + "direct estimates" + ) expect_true(is.data.frame(result)) }) } diff --git a/vignettes/demographics-vignette.Rmd b/vignettes/demographics-vignette.Rmd index 10fb43d..e789856 100644 --- a/vignettes/demographics-vignette.Rmd +++ b/vignettes/demographics-vignette.Rmd @@ -55,7 +55,8 @@ education1 <- demo_education( head(education1, n = 3) -# at least bachelors degree - requires arguments: area, areatype, education, sex, race +# at least bachelors degree - requires arguments: +# area, areatype, education, sex, race education2 <- demo_education( area = "usa", areatype = "state",