Skip to content

Commit

Permalink
Merge pull request #40 from getwilds/documentation
Browse files Browse the repository at this point in the history
modified documentation
  • Loading branch information
realbp authored Feb 29, 2024
2 parents 12443f7 + 33e016c commit 9145720
Show file tree
Hide file tree
Showing 34 changed files with 336 additions and 182 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(demo_crowding)
export(area)
export(demo_education)
export(demo_food)
export(demo_income)
Expand All @@ -19,7 +19,7 @@ export(risk_colorectal_screening)
export(risk_diet_exercise)
export(risk_smoking)
export(risk_vaccines)
export(risk_whealth)
export(risk_women_health)
importFrom(cdlTools,fips)
importFrom(cli,cli_abort)
importFrom(dplyr,filter)
Expand Down
6 changes: 6 additions & 0 deletions R/demo-crowding.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
#' areatype = "hsa",
#' race = "black")
#' }
#'

area = "wa"
areatype = "county"
race = "all races (includes hispanic)"

demo_crowding <- function(area, areatype, race) {

crowding = "00027"
Expand Down
2 changes: 1 addition & 1 deletion R/handle-screening.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ handle_screening <- function(screening) {
"had colonoscopy in past 10 years, ages 50-75" = "v302",

"home blood stool test in the past year, ages 45-75" = "v520",
"receieved at least one recommended crc test, ages 45-75" = "v521"
"received at least one recommended crc test, ages 45-75" = "v521"

#removed from scp
# "ever had colorectal endoscopy (sigmoidoscopy or colonoscopy), ages 50+" = "v09",
Expand Down
11 changes: 4 additions & 7 deletions R/handle-whealth.R → R/handle-women_health.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' This function returns a matching code value for a Women's Health for the api to use to get data from State Cancer Profiles
#'
#' @param whealth Either "mammogram in past 2 years, ages 50-74", "mammogram in past 2 years, ages 40+",
#' @param women_health Either "mammogram in past 2 years, ages 50-74", "mammogram in past 2 years, ages 40+",
#' "pap smear in past 3 years, no hysterectomy, ages 21-65",
#' "pap smear in past 3 years, no hysterectomy, ages 18+"
#'
Expand All @@ -16,8 +16,8 @@
#' \dontrun{
#' handle_whealth("mammogram in past 2 years, ages 50-74")
#' }
handle_whealth <- function(whealth) {
whealth <- tolower(whealth)
handle_women_health <- function(women_health) {
women_health <- tolower(women_health)

whealth_mapping <- c(
"mammogram in past 2 years, ages 50-74" = "v05",
Expand All @@ -29,14 +29,11 @@ handle_whealth <- function(whealth) {
# "pap smear in past 3 years, no hysterectomy, ages 18+" = "v11"
)

whealth_code <- whealth_mapping[whealth]
whealth_code <- whealth_mapping[women_health]

if (is.na(whealth_code)) {
stop("Invalid womens health input, please check the documentation for valid inputs")
}

return(as.character(whealth_code))
}


handle_whealth("pap smear in past 3 years, no hysteroetomy, ages 21-65")
2 changes: 1 addition & 1 deletion R/incidence-cancer.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @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, "Age Adjusted Incidence Rate", "Lower 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"
#'
Expand Down
2 changes: 1 addition & 1 deletion R/mortality-cancer.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' @param age Either "all ages", "ages <50", "ages 50+", "ages <65", "ages 65+", ages <15, ages <20
#' @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 ***?",
#' @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"
Expand Down
1 change: 0 additions & 1 deletion R/process-response.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ process_response <- function(resp) {
paste(collapse = "\n") %>%
(\(x) read.csv(textConnection(x), header=TRUE, colClasses = "character"))()


column <- c("Health.Service.Area", "County", "State")[c("Health.Service.Area", "County", "State") %in% colnames(resp)]

resp <- resp %>%
Expand Down
9 changes: 5 additions & 4 deletions R/risk-alcohol.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
#' "asian or pacific islander (includes hispanic)","hispanic (any race)
#' @param sex Either "both sexes", "male", "female"
#'
#' @returns A data frame with the following columns "State", "FIPS", "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
#'
#' @examples
#' \dontrun{
#' risk_alcohol(paste("binge drinking (4+ drinks on one occasion for women,",
#' "5+ drinks for one occasion for men), ages 21+"),
#' "all races (includes hispanic)", "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")
#' }
risk_alcohol <- function(alcohol, race, sex) {

Expand Down
27 changes: 16 additions & 11 deletions R/risk-colorectal-screening.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,46 @@
#'
#' This function returns a data frame from Colorectal Screening in State Cancer Profiles
#'
#' @param screening One of the following values: "home blood stool test in the past year, ages 45-75",
#' "receieved at least one recommended crc test, ages 45-75",
#' "ever had fobt, ages 50-75",
#' @param screening One of the following values: "ever had fobt, ages 50-75",
#' "guidance sufficient crc, ages 50-75",
#' "had colonoscopy in past 10 years, ages 50-75"
#' "home blood stool test in the past year, ages 45-75"
#' "received at least one recommended crc test, ages 45-75"
#' @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)
#' @param sex Either "both sexes", "male", "female"
#' @param area A state/territory abbreviation or USA.
#'
#' @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{
#' risk_colorectal_screening("home blood stool test in the past year, ages 45-75",
#' "all races (includes hispanic)","both sexes")
#' risk_colorectal_screening("ever had fobt, ages 50-75", area="usa")
#' risk_colorectal_screening("ever had fobt, ages 50-75", area="wa")
#' 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 <- function(screening, race=NULL, sex=NULL, area=NULL) {

req <- create_request("risk")

screening_type_1 = c("home blood stool test in the past year, ages 45-75",
"receieved at least one recommended crc test, ages 45-75")
"received at least one recommended crc test, ages 45-75")

screening_type_2 = c("ever had fobt, ages 50-75",
"guidance sufficient crc, ages 50-75",
"had colonoscopy in past 10 years, ages 50-75")

if (screening %in% screening_type_1 && (is.null(race) || is.null(sex))) {
cli_abort("For this screening type, Race and Sex must not be NULL")
if (screening %in% screening_type_1 && ((is.null(race) || is.null(sex)) || !is.null(area))) {
cli_abort("For this screening type, Race and Sex must not be NULL, and Area must be NULL")
} else if (screening %in% screening_type_2 && (is.null(area) || (!is.null(race) || !is.null(sex)))) {
cli_abort("for this screening type, area must NOT be NULL and Race and Sex must be NULL")
}
Expand Down
8 changes: 5 additions & 3 deletions R/risk-diet-exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
#' "asian or pacific islander (includes hispanic)","hispanic (any race)
#' @param sex Either "both sexes", "male", "female"
#'
#' @returns A data frame with the following columns "State", "FIPS", "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
#'
#' @examples
#' \dontrun{
#' risk_diet_exercise("bmi is healthy, ages 20+", "all races (includes hispanic)", "both sexes")
#' risk_diet_exercise("bmi is obese, high school survey", "all races (includes hispanic)", "males")
#' risk_diet_exercise(diet_exercise = "bmi is healthy, ages 20+",
#' race = "all races (includes hispanic)",
#' sex = "both sexes")
#' risk_diet_exercise(diet_exer"bmi is obese, high school survey", "all races (includes hispanic)", "males")
#' }
risk_diet_exercise <- function(diet_exercise, race, sex) {

Expand Down
31 changes: 19 additions & 12 deletions R/risk-smoking.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#' Access to Smoking Data
#'
#' This function returns a data frame from Smoking in State Cancer Profiles
#'
#' Please note that this function requires very specific arguments for each smoking type
#'
#' @param smoking Either "smoking laws (any)", "smoking laws (bars)", "smoking laws (restaurants)",
#' "smoking laws (workplace)", "smoking laws (workplace; restaurant; & bar)",
Expand All @@ -21,23 +23,28 @@
#' @importFrom cli cli_abort
#' @importFrom stats setNames
#'
#' @returns A data frame with the following columns #"State", "FIPS", "Percent", "Lower CI 95%", "Upper CI 95%", "Number of Respondents"
#' @returns A data frame with the following columns: Area Type, Area Code, "Percent", "Lower CI 95%", "Upper CI 95%", "Number of Respondents"
#'
#' @export
#'
#' @examples
#' \dontrun{
#' risk_smoking("smoking laws (any)")
#' risk_smoking("smokers (stopped for 1 day or longer)", sex="both sexes",
#' datatype="county level modeled estimates", area="wa")
#' risk_smoking("smoking not allowed at work (current smokers)", sex="both sexes",
#' datatype="direct estimates")
#' risk_smoking("former smoker; ages 18+", sex="both sexes",
#' datatype="county level modeled estimates", area="ca")
#' risk_smoking("smokers (ever); ages 18+", race="hispanic (any race)", sex="both sexes",
#' datatype="direct estimates")
#' risk_smoking("smokers (current); ages 18+", race="all races (includes hispanic)",
#' sex="both sexes", datatype="county level modeled estimates", area="wa")
#' 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 <- function(smoking, race=NULL, sex=NULL, datatype=NULL, area=NULL) {

Expand Down
9 changes: 6 additions & 3 deletions R/risk-vaccines.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
#' "percent with up to date hpv vaccination coverage, ages 13-17"
#' @param sex Either "both sexes", "males", "females"
#'
#' @returns A data frame with the following columns "State", "FIPS", "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
#'
#' @examples
#' \dontrun{
#' risk_vaccines("percent with up to date hpv vaccination coverage, ages 13-15", "both sexes")
#' risk_vaccines("percent with up to date hpv vaccination coverage, ages 13-17", "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")
#' }
risk_vaccines <- function(vaccine, sex) {

Expand Down
26 changes: 16 additions & 10 deletions R/risk-womens-health.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@
#'
#' This function returns a data frame from Women's Health in State Cancer Profiles
#'
#' @param whealth Either "mammogram in past 2 years, ages 50-74", "mammogram in past 2 years, ages 40+",
#' @param women_health Either "mammogram in past 2 years, ages 50-74", "mammogram in past 2 years, ages 40+",
#' "pap smear in past 3 years, no hysterectomy, ages 21-65"
#' @param race One of the following values: "all races (includes hispanic)", "white (non-hispanic)",
#' "black (non-hispanic)", "amer. indian / ak native (non-hispanic)",
#' "asian / pacific islander (non-hispanic)","hispanic (any race)"
#' @param datatype Either "direct estimates" or "county level modeled estimates"
#' @param area A state/territory abbreviation or USA.
#'
#' @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{
#' risk_whealth("mammogram in past 2 years, ages 50-74",
#' "all races (includes hispanic)", "direct estimates")
#' risk_whealth("pap smear in past 3 years, no hysterectomy, ages 21-65",
#' "all races (includes hispanic)", "county level modeled estimates", "wa")
#' risk_whealth("pap smear in past 3 years, no hysteroetomy, ages 21-65", "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)")
#' }
risk_whealth <- function(whealth, race, datatype="direct estimates", area=NULL) {
risk_women_health <- function(women_health, race, datatype="direct estimates", area=NULL) {

req <- create_request("risk")

Expand All @@ -41,7 +47,7 @@ risk_whealth <- function(whealth, race, datatype="direct estimates", area=NULL)
resp <- req %>%
req_url_query(
topic="women",
risk=handle_whealth(whealth),
risk=handle_women_health(women_health),
race=handle_race(race),
type="risk",
sortVariableName="percent",
Expand All @@ -65,7 +71,7 @@ risk_whealth <- function(whealth, race, datatype="direct estimates", area=NULL)
resp <- process_screening(resp)

if (datatype == "county level modeled estimates") {
if(whealth == "pap smear in past 3 years, no hysterectomy, ages 21-65") {
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"))
} else {
Expand Down
12 changes: 9 additions & 3 deletions man/demo_crowding.Rd → man/area.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions man/demo_education.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9145720

Please sign in to comment.