From 5adc5edff71e943ca4e62550cfd3057fab090b4b Mon Sep 17 00:00:00 2001 From: realbp Date: Wed, 28 Feb 2024 11:32:18 -0800 Subject: [PATCH] edited documentation --- R/demo-education.R | 22 ++++++++++++++------ R/demo-food-access.R | 18 +++++++++++++---- R/demo-income.R | 19 +++++++++++++---- R/demo-insurance.R | 28 +++++++++++++++++--------- R/demo-mobility.R | 16 +++++++++++---- R/demo-non-english-language.R | 13 ++++++++---- R/demo-population.R | 23 ++++++++++++++++----- R/demo-poverty.R | 18 +++++++++++++---- R/demo-svi.R | 11 +++++++--- R/demo-workforce.R | 19 +++++++++++++---- R/handle-race.R | 4 +++- R/incidence-cancer.R | 16 ++++++++------- R/mortality-cancer.R | 6 +++--- man/incidence_cancer.Rd | 2 +- tests/testthat/test-incidence-cancer.R | 16 +++++++-------- tests/testthat/test-mortality-cancer.R | 14 ++++++------- 16 files changed, 171 insertions(+), 74 deletions(-) diff --git a/R/demo-education.R b/R/demo-education.R index b4d1563..f8b7f33 100644 --- a/R/demo-education.R +++ b/R/demo-education.R @@ -6,7 +6,7 @@ #' @param areatype Either "county", "hsa" (Health service area), or "state" #' @param education Either "less than 9th grade", "at least high school", "at least bachelors degree" #' @param sex Either "both sexes", "male", "female" -#' @param race One of the following values: "All Races (includes Hispanic)", "white (includes hispanic)" = "01", +#' @param race One of the following values: "All Races (includes Hispanic)", "white (includes hispanic)", #' "white non-hispanic","black","amer. indian/alaskan native (includes hispanic)", #' "asian or pacific islander (includes hispanic)","hispanic (any race) #' @@ -14,16 +14,26 @@ #' @importFrom cli cli_abort #' @importFrom stats setNames #' -#' @returns A data frame with the following columns "County", "FIPS", "Percent", "Households", "Rank" +#' @returns A data frame with the following columns: Area Type, Area Code, "Percent", "Households", "Rank" #' #' @export #' #' @examples #' \dontrun{ -#' demo_education("wa", "county", "at least high school", "males") -#' demo_education("usa", "state", "at least bachelors degree", "both sexes", -#' "all races (includes hispanic)") -#' demo_education("pr", "hsa", "less than 9th grade") +#' demo_education(area = "wa", +#' areatype = "county", +#' education = "at least high school", +#' sex = "males") +#' +#' demo_education(area = "usa", +#' areatype = "state", +#' education = "at least bachelors degree", +#' sex = "both sexes", +#' race = "all races (includes hispanic)") +#' +#' demo_education(area = "pr", +#' areatype = "hsa", +#' education = "less than 9th grade") #' } demo_education <- function(area, areatype, education, sex=NULL, race=NULL) { diff --git a/R/demo-food-access.R b/R/demo-food-access.R index b4d521d..b0cfb9c 100644 --- a/R/demo-food-access.R +++ b/R/demo-food-access.R @@ -13,15 +13,25 @@ #' @importFrom dplyr mutate #' @importFrom stats setNames #' -#' @returns A data frame with the following columns "County", "FIPS", "Value", "People" +#' @returns A data frame with the following columns: Area Type, Area Code, "Value", "People" #' #' @export #' #' @examples #' \dontrun{ -#' demo_food("wa", "county", "food insecurity", "black") -#' demo_food("usa", "state", "limited access to healthy food") -#' demo_food("pr", "county", "food insecurity", "all races (includes hispanic)") +#' demo_food(area = "wa", +#' areatype = "county", +#' food = "food insecurity", +#' race = "black") +#' +#' demo_food(area = "usa", +#' areatype = "state", +#' food = "limited access to healthy food") +#' +#' demo_food(area = "pr", +#' areatype = "county", +#' food = "food insecurity", +#' race = "all races (includes hispanic)") #' } demo_food <- function(area, areatype, food, race=NULL) { diff --git a/R/demo-income.R b/R/demo-income.R index 5abee0d..768f4fe 100644 --- a/R/demo-income.R +++ b/R/demo-income.R @@ -14,15 +14,26 @@ #' @importFrom dplyr mutate #' @importFrom stats setNames #' -#' @returns A data frame with the following columns "County", "FIPS", "Dollars", "Rank" +#' @returns A data frame with the following columns: Area Type, Area Code, "Dollars", "Rank" #' #' @export #' #' @examples #' \dontrun{ -#' demo_income("wa", "county", "median family income", "all races (includes hispanic)") -#' demo_income("usa", "state", "median family income", "all races (includes hispanic)") -#' demo_income("pr", "county", "median family income", "all races (includes hispanic)") +#' demo_income(area = "wa", +#' areatype = "county", +#' income = "median family income", +#' race = "all races (includes hispanic)") +#' +#' demo_income(area = "usa", +#' areatype = "state", +#' income = "median family income", +#' race = "all races (includes hispanic)") +#' +#' demo_income(area = "pr", +#' areatype = "county", +#' income = "median family income", +#' race = "all races (includes hispanic)") #' } demo_income <- function(area, areatype, income, race) { diff --git a/R/demo-insurance.R b/R/demo-insurance.R index 59df1ea..d9dff34 100644 --- a/R/demo-insurance.R +++ b/R/demo-insurance.R @@ -20,20 +20,30 @@ #' @importFrom httr2 req_url_query req_perform #' @importFrom cli cli_abort #' -#' @returns A data frame with the following columns "County", "FIPS", "Percent", "People", "Rank" +#' @returns A data frame with the following columns: Area Type, Area Code, "Percent", "People", "Rank" #' #' @export #' #' @examples #' \dontrun{ -#' demo_insurance("usa", "state", "% Insured in demographic group, all income levels", -#' "both sexes", "under 19 years", "all races (includes hispanic)") -#' demo_insurance("wa", "hsa", "% Insured in demographic group, all income levels", -#' "males", "18 to 64 years") -#' demo_insurance("dc", "county", "% Insured in demographic group, all income levels", -#' "males", "18 to 64 years") -#' demo_insurance("usa", "state", "% Insured in demographic group, all income levels", -#' "both sexes", "18 to 64 years", "hispanic (any race)") +#' demo_insurance(area = "usa", +#' areatype = "state", +#' insurance = "% Insured in demographic group, all income levels", +#' sex = "both sexes", +#' age = "under 19 years", +#' race = "all races (includes hispanic)") +#' +#' demo_insurance(area = "wa", +#' areatype = "hsa", +#' insurance = "% Insured in demographic group, all income levels", +#' sex = "males", +#' age = "18 to 64 years") +#' +#' demo_insurance(area = "dc", +#' areatype = "county", +#' insurance = "% Insured in demographic group, all income levels", +#' sex = "males", +#' age = "18 to 64 years") #' } demo_insurance <- function(area, areatype, insurance, sex, age, race=NULL) { diff --git a/R/demo-mobility.R b/R/demo-mobility.R index 908a3e9..29c83de 100644 --- a/R/demo-mobility.R +++ b/R/demo-mobility.R @@ -12,15 +12,23 @@ #' @importFrom cli cli_abort #' @importFrom stats setNames #' -#' @returns A data frame with the following columns "County", "FIPS", "Percent", "People", "Rank" +#' @returns A data frame with the following columns: Area Type, Area Code, "Percent", "People", "Rank" #' #' @export #' #' @examples #' \dontrun{ -#' demo_mobility("WA", "county", "moved, different county, same state (in past year)") -#' demo_mobility("usa", "state", "moved, same county (in past year)") -#' demo_mobility("dc", "hsa", "moved, same county (in past year)") +#' demo_mobility(area = "WA", +#' areatype = "county", +#' mobility = "moved, different county, same state (in past year)") +#' +#' demo_mobility(area = "usa", +#' areatype = "state", +#' mobility = "moved, same county (in past year)") +#' +#' demo_mobility(area = "dc", +#' areatype = "hsa", +#' mobility = "moved, same county (in past year)") #' } demo_mobility <- function(area, areatype, mobility) { diff --git a/R/demo-non-english-language.R b/R/demo-non-english-language.R index e57056a..e754f86 100644 --- a/R/demo-non-english-language.R +++ b/R/demo-non-english-language.R @@ -8,14 +8,19 @@ #' @importFrom httr2 req_url_query req_perform #' @importFrom stats setNames #' -#' @returns A data frame with the following columns "County", "FIPS", "Percent", "Households", "Rank" +#' @returns A data frame with the following columns: Area Type, Area Code, "Percent", "Households", "Rank" #' #' @export #' #' @examples -#' demo_language("WA", "county") -#' demo_language("dc", "hsa") -#' demo_language("usa", "state") +#' demo_language(area = "WA", +#' areatype = "county") +#' +#' demo_language(area = "dc", +#' areatype = "hsa") +#' +#' demo_language(area = "usa", +#' areatype = "state") demo_language <- function(area, areatype) { req <- create_request("demographics") diff --git a/R/demo-population.R b/R/demo-population.R index fe059f2..3a38ddd 100644 --- a/R/demo-population.R +++ b/R/demo-population.R @@ -8,22 +8,35 @@ #' "american indian/alaska native", "asian/pacific islander", "black", "foreign born", "hispanic", #' "non-hispanic (origin recode)", "white", "males", "females" #' @param race One of the following values: "american indian/alaska native", "asian/pacific islander", -#' "black", "foreign born", "hispanic", "non-hispanic (origin recode)", "white" +#' "black", "hispanic", "white (includes hispanic)", "white non-hispanic", "hispanic (any race)" #' @param sex Either "both sexes", "male", "female" #' #' @importFrom httr2 req_url_query req_perform #' @importFrom cli cli_abort #' @importFrom stats setNames #' -#' @returns A data frame with the following columns "County", "FIPS", "Percent", "Households", "Rank" +#' @returns A data frame with the following columns: Area Type, Area Code, "Percent", "Households", "Rank" #' #' @export #' #' @examples #' \dontrun{ -#' demo_population("WA", "county", "asian/pacific islander", sex="females") -#' demo_population("dc", "hsa", "foreign born", "black", "females") -#' demo_population("usa", "state", "foreign born", "black", "females") +#' demo_population(area = "WA", +#' areatype = "county", +#' population = "asian/pacific islander", +#' sex="females") +#' +#' demo_population(area = "dc", +#' areatype = "hsa", +#' population = "foreign born", +#' race = "black", +#' sex = "females") +#' +#' demo_population(area = "usa", +#' areatype = "state", +#' population = "foreign born", +#' race = "hispanic (any race)", +#' sex = "females") #' #' } demo_population <- function(area, areatype, population, race=NULL, sex=NULL) { diff --git a/R/demo-poverty.R b/R/demo-poverty.R index 34a488f..77939b2 100644 --- a/R/demo-poverty.R +++ b/R/demo-poverty.R @@ -13,15 +13,25 @@ #' @importFrom httr2 req_url_query req_perform #' @importFrom stats setNames #' -#' @returns A data frame with the following columns "County", "FIPS", "Percent", "Households", "Rank" +#' @returns A data frame with the following columns: Area Type, Area Code, "Percent", "Households", "Rank" #' #' @export #' #' @examples #' \dontrun{ -#' demo_poverty("WA", "county", "persistent poverty") -#' demo_poverty("usa", "state", "families below poverty", "black") -#' demo_poverty("dc", "hsa", "families below poverty", "All Races (includes Hispanic)") +#' demo_poverty(area = "WA", +#' areatype = "county", +#' poverty = "persistent poverty") +#' +#' demo_poverty(area = "usa", +#' areatype = "state", +#' poverty = "families below poverty", +#' race = "black") +#' +#' demo_poverty(area = "dc", +#' areatype = "hsa", +#' poverty = "families below poverty", +#' race = "All Races (includes Hispanic)") #' } demo_poverty <- function(area, areatype, poverty, race=NULL, sex=NULL) { diff --git a/R/demo-svi.R b/R/demo-svi.R index 902c460..79821cd 100644 --- a/R/demo-svi.R +++ b/R/demo-svi.R @@ -14,9 +14,14 @@ #' #' @examples #' \dontrun{ -#' demo_svi("WA", "overall") -#' demo_svi("usa", "overall") -#' demo_svi("dc", "socioeconomic status") +#' demo_svi(area = "WA", +#' svi = "overall") +#' +#' demo_svi(area = "usa", +#' svi = "overall") +#' +#' demo_svi(area = "dc", +#' svi = "socioeconomic status") #' } demo_svi <- function(area, svi) { diff --git a/R/demo-workforce.R b/R/demo-workforce.R index 3f65551..904ad3d 100644 --- a/R/demo-workforce.R +++ b/R/demo-workforce.R @@ -12,15 +12,26 @@ #' @importFrom httr2 req_url_query req_perform #' @importFrom stats setNames #' -#' @returns A data frame with the following columns "County", "FIPS", "Percent", "People Unemployed", "Rank" +#' @returns A data frame with the following columns: Area Type, Area Code, "Percent", "People Unemployed", "Rank" #' #' @export #' #' @examples #' \dontrun{ -#' demo_workforce("WA", "county", "all races (includes hispanic)", "both sexes") -#' demo_workforce("usa", "state", "all races (includes hispanic)", "females") -#' demo_workforce("pr", "hsa", "all races (includes hispanic)", "both sexes") +#' demo_workforce(area = "WA", +#' areatype = "county", +#' race = "all races (includes hispanic)", +#' sex = "both sexes") +#' +#' demo_workforce(area = "usa", +#' areatype = "state", +#' race = "all races (includes hispanic)", +#' sex = "females") +#' +#' demo_workforce(area = "pr", +#' areatype = "hsa", +#' race = "all races (includes hispanic)", +#' sex = "both sexes") #' } demo_workforce <- function(area, areatype, race, sex) { diff --git a/R/handle-race.R b/R/handle-race.R index 4027dc2..e11a27d 100644 --- a/R/handle-race.R +++ b/R/handle-race.R @@ -29,7 +29,9 @@ handle_race <- function(race) { "black" = "02", "black (includes hispanic)" = "02", "amer. indian/alaskan native (includes hispanic)" = "03", - "all ages, asian or pacific islander (includes hispanic)" = "04", + "american indian/alaska native" = "03", + "asian or pacific islander (includes hispanic)" = "04", + "asian/pacific islander" = "04", "hispanic (any race)" = "05", #screening and risk factors diff --git a/R/incidence-cancer.R b/R/incidence-cancer.R index 369a4cb..457b3a9 100644 --- a/R/incidence-cancer.R +++ b/R/incidence-cancer.R @@ -17,10 +17,9 @@ #' @param stage Either "all stages" or "late stage (regional & distant)" #' @param year Either "latest 5 year average", "latest single year (us by state)" #' -#' @returns A data frame with the following columns Areatype, 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 Areatype, 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 #' @@ -45,7 +44,7 @@ #' year = "latest single year (us by state)") #' #' incidence_cancer(area = "wa", -#' areatype = "county", +#' areatype = "hsa", #' cancer = "ovary", #' race = "all races (includes hispanic)", #' sex = "females", @@ -114,12 +113,15 @@ incidence_cancer <- function(area, areatype, cancer, race, sex, age, stage, year 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, "FIPS", "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, "FIPS", "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 68ff467..a32c5ad 100644 --- a/R/mortality-cancer.R +++ b/R/mortality-cancer.R @@ -19,9 +19,9 @@ #' @param year Either "latest 5 year average", "latest single year (us by state)" #' #' @returns A data frame with the following columns Areatype, 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" +#' "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 #' diff --git a/man/incidence_cancer.Rd b/man/incidence_cancer.Rd index 1e71865..83aac18 100644 --- a/man/incidence_cancer.Rd +++ b/man/incidence_cancer.Rd @@ -59,7 +59,7 @@ incidence_cancer(area = "usa", year = "latest single year (us by state)") incidence_cancer(area = "wa", - areatype = "county", + areatype = "hsa", cancer = "ovary", race = "all races (includes hispanic)", sex = "females", diff --git a/tests/testthat/test-incidence-cancer.R b/tests/testthat/test-incidence-cancer.R index c7d401c..32c8203 100644 --- a/tests/testthat/test-incidence-cancer.R +++ b/tests/testthat/test-incidence-cancer.R @@ -5,7 +5,7 @@ # tests class and typeof output test_that("Output data type is correct", { output <- incidence_cancer("wa", "county", "all cancer sites", "black (non-hispanic)", - "both sexes", "ages 65+", "all stages") + "both sexes", "ages 65+", "all stages", "latest 5 year average") expect_true(inherits(output, "data.frame")) }) @@ -19,7 +19,7 @@ cancer_options <- c("all cancer sites","bladder", "brain & ons", "colon & rectum for (option in cancer_options) { test_that("incidence cancer returns non-empty data frame", { result <- incidence_cancer("wa", "county", option, "all races (includes hispanic)", - "both sexes", "all ages", "all stages") + "both sexes", "all ages", "all stages", "latest 5 year average") expect_true(is.data.frame(result)) }) } @@ -31,7 +31,7 @@ for (option in female_cancer_options) { test_that("incidence female cancer returns non-empty data frame", { result <- incidence_cancer("wa", "county", option, "all races (includes hispanic)", "females", - "ages 50+", "all stages") + "ages 50+", "all stages", "latest 5 year average") expect_true(is.data.frame(result)) }) @@ -39,11 +39,11 @@ 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"), + "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"), + "males", "ages <20", "all stages", "latest 5 year average"), prostate = incidence_cancer("usa", "state", "prostate", "all races (includes hispanic)", - "males", "ages 50+", "all stages") + "males", "ages 50+", "all stages", "latest 5 year average") ) for (option_name in names(childhood_male_cancer_options)) { @@ -56,9 +56,9 @@ for (option_name in names(childhood_male_cancer_options)) { #incidence_cancer must have 14 columns test_that("incidence_cancer has correct number of columns", { df1 <- incidence_cancer("wa", "county", "all cancer sites", "black (non-hispanic)", - "both sexes", "ages 65+", "all stages") + "both sexes", "ages 65+", "all stages", "latest 5 year average") df2 <- incidence_cancer("usa", "state", "lung & bronchus", "all races (includes hispanic)", "males", - "ages 50+", "late stage (regional & distant)") + "ages 50+", "late stage (regional & distant)", "latest 5 year average") expected_columns1 <- 13 expected_columns2 <- 10 expect_equal(ncol(df1), expected_columns1) diff --git a/tests/testthat/test-mortality-cancer.R b/tests/testthat/test-mortality-cancer.R index 71efb4d..7a05fbc 100644 --- a/tests/testthat/test-mortality-cancer.R +++ b/tests/testthat/test-mortality-cancer.R @@ -5,7 +5,7 @@ # tests class and typeof output test_that("Output data type is correct", { output <- mortality_cancer("wa", "county", "all cancer sites", "black (non-hispanic)", - "both sexes", "ages 65+") + "both sexes", "ages 65+", "latest 5 year average") expect_true(inherits(output, "data.frame")) }) @@ -19,7 +19,7 @@ cancer_options <- c("all cancer sites","bladder", "brain & ons", "colon & rectum for (option in cancer_options) { test_that("mortality cancer returns non-empty data frame", { result <- mortality_cancer("wa", "county", option, "all races (includes hispanic)", - "both sexes", "all ages") + "both sexes", "all ages", "latest 5 year average") expect_true(is.data.frame(result)) }) } @@ -28,7 +28,7 @@ female_cancer_options <- c("breast (female)", "cervix", "ovary", "uterus (corpus for (option in female_cancer_options) { test_that("mortality female cancer returns non-empty data frame", { - result <- mortality_cancer("wa", "county", option, "all races (includes hispanic)", "females", "ages 50+") + result <- mortality_cancer("wa", "county", option, "all races (includes hispanic)", "females", "ages 50+", "latest 5 year average") expect_true(is.data.frame(result)) }) @@ -36,11 +36,11 @@ 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"), + "males", "ages <20", "latest 5 year average"), childhood20 = mortality_cancer("ca", "hsa", "childhood (ages <20, all sites)", "all races (includes hispanic)", - "males", "ages <20"), + "males", "ages <20", "latest 5 year average"), prostate = mortality_cancer("usa", "state", "prostate", "all races (includes hispanic)", - "males", "ages 50+") + "males", "ages 50+", "latest 5 year average") ) for (option_name in names(childhood_male_cancer_options)) { @@ -53,7 +53,7 @@ for (option_name in names(childhood_male_cancer_options)) { #mortality_cancer must have 14 columns test_that("mortality_cancer has correct number of columns", { df <- mortality_cancer("wa", "county", "all cancer sites", "black (non-hispanic)", - "both sexes", "ages 65+") + "both sexes", "ages 65+", "latest 5 year average") expected_columns <- 14 expect_equal(ncol(df), expected_columns)