Skip to content

Commit

Permalink
Merge pull request #90 from getwilds/dev
Browse files Browse the repository at this point in the history
Dev to main
  • Loading branch information
realbp authored Mar 21, 2024
2 parents e5df87e + c6619b2 commit 7da998f
Show file tree
Hide file tree
Showing 47 changed files with 1,508 additions and 408 deletions.
1 change: 0 additions & 1 deletion .Rapp.history

This file was deleted.

2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^man-roxygen$
^vignettes/\.RData$
4 changes: 4 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters: linters_with_defaults(
line_length_linter(120),
cyclocomp_linter(complexity_limit = 150)
)
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ Suggests:
testthat
Config/testthat/edition: 3
VignetteBuilder: knitr
Depends:
R (>= 2.10)
4 changes: 4 additions & 0 deletions R/.lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters: linters_with_defaults(
line_length_linter(120),
cyclocomp_linter(complexity_limit = 150)
)
14 changes: 3 additions & 11 deletions R/demo-crowding.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#' Cancer Profiles.
#'
#' @param area A state/territory abbreviation or USA.
#' @param areatype One of the following values:
#' - `"county"`
#' - `"hsa"` (Health Service Area)
#' - `"state"`.
#' @template param-areatype
#' @param crowding The only permissible value is
#' `"household with >1 person per room"`.
#' @param race
Expand All @@ -26,7 +23,7 @@
#'
#' @returns A data frame with the following columns: Area, Area Code,
#' Percent, Households, Rank.
#'
#'
#' @family demographics
#'
#' @export
Expand Down Expand Up @@ -55,7 +52,6 @@
#' )
#' }
demo_crowding <- function(area, areatype, crowding, race) {

req <- create_request("demographics")

resp <- req %>%
Expand All @@ -74,13 +70,9 @@ demo_crowding <- function(area, areatype, crowding, race) {

resp <- process_resp(resp, "demographics")

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

resp %>%
setNames(c(
area_type,
area_code,
get_area(areatype),
"Percent",
"Households",
"Rank"
Expand Down
20 changes: 5 additions & 15 deletions R/demo-education.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
#' State Cancer Profiles.
#'
#' @param area A state/territory abbreviation or USA.
#' @param areatype One of the following values:
#' - `"county"`
#' - `"hsa"` (Health Service Area)
#' - `"state"`.
#' @template param-areatype
#' @param education One of the following values:
#' - `"less than 9th grade"`
#' - `"at least high school"`
#' - `"at least bachelors degree"`.
#' @param sex One of the following values:
#' - `"both sexes"`
#' - `"male"`
#' - `"female"`.
#' @template param-sex
#' @param race One of the following values:
#' - `"All Races (includes Hispanic)"`
#' - `"White (includes Hispanic)"`
Expand All @@ -31,7 +25,7 @@
#'
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Percent, Households, Rank.
#'
#'
#' @family demographics
#'
#' @export
Expand Down Expand Up @@ -96,17 +90,13 @@ demo_education <- function(area, areatype, education, sex = NULL, race = NULL) {
req_perform()

resp <- process_resp(resp, "demographics")

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

resp %>%
setNames(c(
area_type,
area_code,
get_area(areatype),
"Percent",
"Households",
"Rank"
)) %>%
)) %>%
mutate(across(c("Percent", "Households"), \(x) as.numeric(x)))
}
9 changes: 3 additions & 6 deletions R/demo-food-access.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#'
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Value, People.
#'
#'
#' @family demographics
#'
#' @export
Expand Down Expand Up @@ -79,16 +79,13 @@ demo_food <- function(area, areatype, food, race = NULL) {

resp <- process_resp(resp, "demographics")

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

if (food == "limited access to healthy food") {
resp %>%
setNames(c(area_type, area_code, "Percent", "People")) %>%
setNames(c(get_area(areatype), "Percent", "People")) %>%
mutate(across(c("Percent", "People"), \(x) as.numeric(x)))
} else if (food == "food insecurity") {
resp %>%
setNames(c(area_type, area_code, "Percent")) %>%
setNames(c(get_area(areatype), "Percent")) %>%
mutate(across(c("Percent"), \(x) as.numeric(x)))
}
}
7 changes: 2 additions & 5 deletions R/demo-income.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#'
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Dollars, Rank.
#'
#'
#' @family demographics
#'
#' @export
Expand Down Expand Up @@ -68,10 +68,7 @@ demo_income <- function(area, areatype, income, race) {

resp <- process_resp(resp, "demographics")

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

resp %>%
setNames(c(area_type, area_code, "Dollars", "Rank")) %>%
setNames(c(get_area(areatype), "Dollars", "Rank")) %>%
mutate(across(c("Dollars"), \(x) as.numeric(x)))
}
17 changes: 4 additions & 13 deletions R/demo-insurance.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#' from State Cancer Profiles.
#'
#' @param area A state/territory abbreviation or USA.
#' @param areatype One of the following values:
#' - `"county"`
#' - `"hsa"` (Health Service Area)
#' - `"state"`.
#' @template param-areatype
#' @param insurance One of the following values:
#' - `"% Insured in demographic group, all income levels"`
#' - `"% Insured in demographic group, people at or below 138% of Poverty"`
Expand All @@ -21,10 +18,7 @@
#' - `"% uninsured in demographic group, people at or below 250% of Poverty"`
#' - `"% uninsured in demographic group, people at or below 400% of Poverty"`
#' - `"% uninsured in demographic group, people between 138% - 400% of poverty"`.
#' @param sex One of the following values:
#' - `"both sexes"`
#' - `"male"`
#' - `"female"`.
#' @template param-sex
#' @param age If you specified `"both sexes"` for `sex`
#' choose one of the following values:
#' - `"under 19 years"`
Expand Down Expand Up @@ -55,7 +49,7 @@
#'
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Percent, People, Rank.
#'
#'
#' @family demographics
#'
#' @export
Expand Down Expand Up @@ -132,10 +126,7 @@ demo_insurance <- function(area, areatype, insurance, sex, age, race = NULL) {

resp <- process_resp(resp, "demographics")

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

resp %>%
setNames(c(area_type, area_code, "Percent", "People", "Rank")) %>%
setNames(c(get_area(areatype), "Percent", "People", "Rank")) %>%
mutate(across(c("Percent", "People"), \(x) as.numeric(x)))
}
15 changes: 4 additions & 11 deletions R/demo-mobility.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#' from State Cancer Profiles.
#'
#' @param area A state/territory abbreviation or USA.
#' @param areatype One of the following values:
#' - `"county"`
#' - `"hsa"` (Health Service Area)
#' - `"state"`.
#' @template param-areatype
#' @param mobility The only permissible values are
#' - `"i haven't moved (in past year)"`
#' - `"moved from outside us (in past year)"`
Expand All @@ -21,7 +18,7 @@
#'
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Percent, People, Rank.
#'
#'
#' @family demographics
#'
#' @export
Expand Down Expand Up @@ -64,16 +61,12 @@ demo_mobility <- function(area, areatype, mobility) {

resp <- process_resp(resp, "demographics")

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

resp %>%
setNames(c(
area_type,
area_code,
get_area(areatype),
"Percent",
"People",
"Rank"
)) %>%
)) %>%
mutate(across(c("Percent", "People"), \(x) as.numeric(x)))
}
15 changes: 4 additions & 11 deletions R/demo-non-english-language.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#' from State Cancer Profiles.
#'
#' @param area A state/territory abbreviation or USA.
#' @param areatype One of the following values:
#' - `"county"`
#' - `"hsa"` (Health Service Area)
#' - `"state"`.
#' @template param-areatype
#' @param language The only permissible value is
#' `"language isolation"`.
#'
Expand All @@ -17,7 +14,7 @@
#'
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Percent, Households, Rank.
#'
#'
#' @family demographics
#'
#' @export
Expand Down Expand Up @@ -58,16 +55,12 @@ demo_language <- function(area, areatype, language) {

resp <- process_resp(resp, "demographics")

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

resp %>%
setNames(c(
area_type,
area_code,
get_area(areatype),
"Percent",
"Households",
"Rank"
)) %>%
)) %>%
mutate(across(c("Percent", "Households"), \(x) as.numeric(x)))
}
28 changes: 9 additions & 19 deletions R/demo-population.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#' from State Cancer Profiles.
#'
#' @param area A state/territory abbreviation or USA.
#' @param areatype One of the following values:
#' - `"county"`
#' - `"hsa"` (Health Service Area)
#' - `"state"`.
#' @template param-areatype
#' @param population One of the following values:
#' - `"age under 18"`
#' - `"age 18-39"`
Expand All @@ -32,10 +29,7 @@
#' - `"White (includes Hispanic)"`
#' - `"White non-Hispanic"`
#' - `"Hispanic (Any Race)"`.
#' @param sex One of the following values:
#' - `"both sexes"`
#' - `"male"`
#' - `"female"`.
#' @template param-sex
#'
#' @importFrom httr2 req_url_query req_perform
#' @importFrom cli cli_abort
Expand All @@ -44,7 +38,7 @@
#'
#' @returns A data frame with the following columns:
#' Area Type, Area Code, Percent, Households, Rank.
#'
#'
#' @family demographics
#'
#' @export
Expand Down Expand Up @@ -87,9 +81,9 @@ demo_population <- function(area, areatype, population, race = NULL, sex = NULL)
cli_abort("for males, Race must not be NULL and Sex must be NULL")
} else if (population == "foreign born" && (is.null(race) || is.null(sex))) {
cli_abort("for foreign born, race and sex must not be NULL")
} else if ((population == "american indian/alaska native" || population == "asian/pacific islander" || population == "black" ||
population == "hispanic" || population == "non-hispanic (origin recode)" ||
population == "white") && (is.null(sex) || !is.null(race))) {
} else if ((population == "american indian/alaska native" || population == "asian/pacific islander" ||
population == "black" || population == "hispanic" || population == "non-hispanic (origin recode)" ||
population == "white") && (is.null(sex) || !is.null(race))) {
cli_abort("for races other than foreign born, Sex must not be NULL and race must be NULL")
}

Expand Down Expand Up @@ -117,19 +111,15 @@ demo_population <- function(area, areatype, population, race = NULL, sex = NULL)

resp <- resp %>%
req_perform()

resp <- process_resp(resp, "demographics")

area_type <- get_area(areatype)[1]
area_code <- get_area(areatype)[2]
resp <- process_resp(resp, "demographics")

resp %>%
setNames(c(
area_type,
area_code,
get_area(areatype),
"Percent",
"People",
"Rank"
)) %>%
)) %>%
mutate(across(c("Percent", "People"), \(x) as.numeric(x)))
}
Loading

0 comments on commit 7da998f

Please sign in to comment.