Skip to content

Commit

Permalink
Merge pull request #69 from getwilds/test
Browse files Browse the repository at this point in the history
more linting
  • Loading branch information
realbp authored Mar 8, 2024
2 parents 4f72e87 + 069c53e commit d9bf492
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 57 deletions.
32 changes: 25 additions & 7 deletions R/process-incidence.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Process Cancer Incidence Response Data
#'
#' This function processes the Cancer Incidence response data from State Cancer Profiles
#' This function processes the Cancer Incidence response data
#' from State Cancer Profiles
#'
#' @param resp A response object
#'
Expand All @@ -21,7 +22,7 @@
process_incidence <- function(resp) {
nenv <- new.env()
data("state", envir = nenv)
state.name <- nenv$state.name
state_name <- nenv$state.name

resp_lines <- resp %>%
resp_body_string() %>%
Expand All @@ -31,12 +32,29 @@ process_incidence <- function(resp) {
index_first_line_break <- which(resp_lines == "")[4]
index_second_line_break <- which(resp_lines == "")[5]

resp <- resp_lines[(index_first_line_break + 1):(index_second_line_break - 1)] %>%
resp <- resp_lines[
(index_first_line_break + 1):
(index_second_line_break - 1)
] %>%
paste(collapse = "\n") %>%
(\(x) read.csv(textConnection(x), header = TRUE, colClasses = "character"))()
(
\(x) {
read.csv(textConnection(x),
header = TRUE,
colClasses = "character"
)
}
)()


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

resp <- resp %>%
filter(!!sym(column) != "US (SEER+NPCR)(1)") %>%
Expand All @@ -45,7 +63,7 @@ process_incidence <- function(resp) {

if (column %in% c("Health.Service.Area", "County")) {
resp <- resp %>%
filter(!(!!sym(column) %in% state.name))
filter(!(!!sym(column) %in% state_name))
}
resp
}
32 changes: 25 additions & 7 deletions R/process-mortality.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Process Cancer Mortality Response Data
#'
#' This function processes the Cancer Mortality response data from State Cancer Profiles
#' This function processes the Cancer Mortality response data
#' from State Cancer Profiles
#'
#' @param resp A response object
#'
Expand All @@ -20,7 +21,7 @@
process_mortality <- function(resp) {
nenv <- new.env()
data("state", envir = nenv)
state.name <- nenv$state.name
state_name <- nenv$state.name

resp_lines <- resp %>%
resp_body_string() %>%
Expand All @@ -30,19 +31,36 @@ process_mortality <- function(resp) {
index_first_line_break <- which(resp_lines == "")[4]
index_second_line_break <- which(resp_lines == "")[5]

resp <- resp_lines[(index_first_line_break + 1):(index_second_line_break - 1)] %>%
resp <- resp_lines[
(index_first_line_break + 1):
(index_second_line_break - 1)
] %>%
paste(collapse = "\n") %>%
(\(x) read.csv(textConnection(x), header = TRUE, colClasses = "character"))()
(
\(x) {
read.csv(textConnection(x),
header = TRUE,
colClasses = "character"
)
}
)()


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

resp <- resp %>%
filter(!!sym(column) != "United States")

if (column %in% c("Health.Service.Area", "County")) {
resp <- resp %>%
filter(!(!!sym(column) %in% state.name))
filter(!(!!sym(column) %in% state_name))
}

resp %>%
Expand Down
31 changes: 23 additions & 8 deletions R/process-response.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
process_response <- function(resp) {
nenv <- new.env()
data("state", envir = nenv)
state.name <- nenv$state.name
state_name <- nenv$state.name

resp_lines <- resp %>%
resp_body_string() %>%
Expand All @@ -30,21 +30,36 @@ process_response <- function(resp) {
index_first_line_break <- which(resp_lines == "")[1]
index_second_line_break <- which(resp_lines == "")[2]

resp <- resp_lines[(index_first_line_break + 1):(index_second_line_break - 1)] %>%
resp <- resp_lines[
(index_first_line_break + 1):
(index_second_line_break - 1)
] %>%
paste(collapse = "\n") %>%
(\(x) read.csv(textConnection(x), header = TRUE, colClasses = "character"))()
(
\(x) {
read.csv(textConnection(x),
header = TRUE,
colClasses = "character"
)
}
)()

# resp <- resp %>%
# read.csv(text=.)

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

resp <- resp %>%
filter(!!sym(column) != "United States")

if (column %in% c("Health.Service.Area", "County")) {
resp <- resp %>%
filter(!(!!sym(column) %in% state.name))
filter(!(!!sym(column) %in% state_name))
}
resp %>%
mutate_all(\(x) na_if(x, "N/A")) %>%
Expand Down
18 changes: 12 additions & 6 deletions R/process-screening.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#' process_screening(resp)
#' }
process_screening <- function(resp) {
nenv <- new.env()
data("state", envir = nenv)
state.name <- nenv$state.name

resp_lines <- resp %>%
resp_body_string() %>%
strsplit("\\n") %>%
Expand All @@ -30,9 +26,19 @@ process_screening <- function(resp) {
index_first_line_break <- which(resp_lines == "")[3]
index_second_line_break <- which(resp_lines == "")[4]

resp <- resp_lines[(index_first_line_break + 1):(index_second_line_break - 1)] %>%
resp <- resp_lines[
(index_first_line_break + 1):
(index_second_line_break - 1)
] %>%
paste(collapse = "\n") %>%
(\(x) read.csv(textConnection(x), header = TRUE, colClasses = "character"))()
(
\(x) {
read.csv(textConnection(x),
header = TRUE,
colClasses = "character"
)
}
)()

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

Expand Down
3 changes: 2 additions & 1 deletion R/risk-alcohol.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#' 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+"`.
#' `paste("binge drinking (4+ drinks on one occasion for women,",
#' "5+ drinks for one occasion for men), ages 21+")
#' @param race One of the following values:
#' - `"All Races (includes Hispanic)"`
#' - `"White (non-Hispanic)"`
Expand Down
25 changes: 20 additions & 5 deletions R/test-dput-resp-incd.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Test dput-resp-incidence
#'
#' This function creates a response object from the Incidence section of State Cancer Profiles for
#' This function creates a response object from the Incidence section of
#' State Cancer Profiles to be used in testing
#'
#'
#' @returns A httr2 response object
Expand All @@ -13,12 +14,20 @@
#' }
dput_resp_incd <- function() {
resp <- structure(list(
method = "GET", url = "https://statecancerprofiles.cancer.gov/incidencerates/index.php?stateFIPS=10&areatype=county&cancer=001&race=00&age=157&stage=999&year=0&type=incd&sortVariableName=rate&sortOrder=default&output=1&sex=0",
method = "GET",
url = paste0(
"https://statecancerprofiles.cancer.gov/incidencerates/",
"index.php?stateFIPS=10&areatype=county&cancer=001",
"&race=00&age=157&stage=999&year=0&type=incd&",
"sortVariableName=rate&sortOrder=default&output=1&sex=0"
),
status_code = 200L, headers = structure(list(
date = "Wed, 21 Feb 2024 19:21:05 GMT",
server = "Apache", `content-disposition` = "attachment; filename=\"incd.csv\"",
server = "Apache",
`content-disposition` = "attachment; filename=\"incd.csv\"",
`x-frame-options` = "SAMEORIGIN", `cache-control` = "public, max-age=300",
`content-type` = "text/csv; charset=iso-8859-1", `strict-transport-security` = "max-age=31536000;preload",
`content-type` = "text/csv; charset=iso-8859-1",
`strict-transport-security` = "max-age=31536000;preload",
`set-cookie` = "TKTID=web-dmzst-03; path=/; HttpOnly; Secure",
`cache-control` = "private"
), class = "httr2_headers"),
Expand Down Expand Up @@ -455,10 +464,16 @@ dput_resp_incd <- function() {
0x65, 0x20, 0x50, 0x75, 0x65, 0x72, 0x74, 0x6f, 0x20, 0x52,
0x69, 0x63, 0x6f, 0x2e, 0x0a
)), request = structure(list(
url = "https://statecancerprofiles.cancer.gov/incidencerates/index.php?stateFIPS=10&areatype=county&cancer=001&race=00&age=157&stage=999&year=0&type=incd&sortVariableName=rate&sortOrder=default&output=1&sex=0",
url = paste0(
"https://statecancerprofiles.cancer.gov/incidencerates/",
"index.php?stateFIPS=10&areatype=county&cancer=001",
"&race=00&age=157&stage=999&year=0&type=incd&",
"sortVariableName=rate&sortOrder=default&output=1&sex=0"
),
method = NULL, headers = list(), body = NULL, fields = list(),
options = list(), policies = list()
), class = "httr2_request"),
cache = new.env()
), class = "httr2_response")
return(resp)
}
25 changes: 20 additions & 5 deletions R/test-dput-resp-mortality.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Test dput-resp-mortality
#'
#' This function creates a response object from the Mortality section of State Cancer Profiles for
#' This function creates a response object from the Mortality section of
#' State Cancer Profiles to be used in testing
#'
#'
#' @returns A httr2 response object
Expand All @@ -13,12 +14,20 @@
#' }
dput_resp_mortality <- function() {
resp <- structure(list(
method = "GET", url = "https://statecancerprofiles.cancer.gov/deathrates/index.php?stateFIPS=10&areatype=county&cancer=001&race=00&age=157&year=0&type=death&sortVariableName=rate&sortOrder=default&output=1&sex=0",
method = "GET",
url = paste0(
"https://statecancerprofiles.cancer.gov/deathrates/",
"index.php?stateFIPS=10&areatype=county&cancer=001",
"&race=00&age=157&year=0&type=death&",
"sortVariableName=rate&sortOrder=default&output=1&sex=0"
),
status_code = 200L, headers = structure(list(
date = "Wed, 21 Feb 2024 19:51:18 GMT",
server = "Apache", `content-disposition` = "attachment; filename=\"death.csv\"",
server = "Apache",
`content-disposition` = "attachment; filename=\"death.csv\"",
`x-frame-options` = "SAMEORIGIN", `cache-control` = "public, max-age=300",
`content-type` = "text/csv; charset=iso-8859-1", `strict-transport-security` = "max-age=31536000;preload",
`content-type` = "text/csv; charset=iso-8859-1",
`strict-transport-security` = "max-age=31536000;preload",
`set-cookie` = "TKTID=web-dmzst-02; path=/; HttpOnly; Secure",
`cache-control` = "private"
), class = "httr2_headers"),
Expand Down Expand Up @@ -340,10 +349,16 @@ dput_resp_mortality <- function() {
0x6c, 0x75, 0x64, 0x65, 0x20, 0x50, 0x75, 0x65, 0x72, 0x74,
0x6f, 0x20, 0x52, 0x69, 0x63, 0x6f, 0x2e, 0x0a
)), request = structure(list(
url = "https://statecancerprofiles.cancer.gov/deathrates/index.php?stateFIPS=10&areatype=county&cancer=001&race=00&age=157&year=0&type=death&sortVariableName=rate&sortOrder=default&output=1&sex=0",
url = paste0(
"https://statecancerprofiles.cancer.gov/deathrates/",
"index.php?stateFIPS=10&areatype=county&cancer=001",
"&race=00&age=157&year=0&type=death&",
"sortVariableName=rate&sortOrder=default&output=1&sex=0"
),
method = NULL, headers = list(), body = NULL, fields = list(),
options = list(), policies = list()
), class = "httr2_request"),
cache = new.env()
), class = "httr2_response")
return(resp)
}
25 changes: 20 additions & 5 deletions R/test-dput-resp-risk.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Test dput-resp-demo
#'
#' This function creates a response object from the Demographics section of State Cancer Profiles for
#' This function creates a response object from the Demographics section of
#' State Cancer Profiles to be used in testing
#'
#'
#' @returns A httr2 response object
Expand All @@ -13,12 +14,20 @@
#' }
dput_resp_risk <- function() {
resp <- structure(list(
method = "GET", url = "https://statecancerprofiles.cancer.gov/risk/index.php?topic=colorec&risk=v304&type=risk&sortVariableName=percent&sortOrder=default&output=1&race=00&stateFIPS=44",
method = "GET",
url = paste0(
"https://statecancerprofiles.cancer.gov/risk/",
"index.php?topic=colorec&risk=v304&type=risk&",
"sortVariableName=percent&sortOrder=default&",
"output=1&race=00&stateFIPS=44"
),
status_code = 200L, headers = structure(list(
date = "Tue, 20 Feb 2024 20:40:10 GMT",
server = "Apache", `content-disposition` = "attachment; filename=\"screening_risk.csv\"",
server = "Apache",
`content-disposition` = "attachment; filename=\"screening_risk.csv\"",
`x-frame-options` = "SAMEORIGIN", `cache-control` = "public, max-age=300",
`content-type` = "text/csv; charset=iso-8859-1", `strict-transport-security` = "max-age=31536000;preload",
`content-type` = "text/csv; charset=iso-8859-1",
`strict-transport-security` = "max-age=31536000;preload",
`set-cookie` = "TKTID=web-dmzst-03; path=/; HttpOnly; Secure",
`cache-control` = "private"
), class = "httr2_headers"),
Expand Down Expand Up @@ -154,10 +163,16 @@ dput_resp_risk <- function() {
0x20, 0x50, 0x75, 0x65, 0x72, 0x74, 0x6f, 0x20, 0x52, 0x69,
0x63, 0x6f, 0x2e, 0x0a
)), request = structure(list(
url = "https://statecancerprofiles.cancer.gov/risk/index.php?topic=colorec&risk=v304&type=risk&sortVariableName=percent&sortOrder=default&output=1&race=00&stateFIPS=44",
url = paste0(
"https://statecancerprofiles.cancer.gov/risk/",
"index.php?topic=colorec&risk=v304&type=risk&",
"sortVariableName=percent&sortOrder=default&",
"output=1&race=00&stateFIPS=44"
),
method = NULL, headers = list(), body = NULL, fields = list(),
options = list(), policies = list()
), class = "httr2_request"),
cache = new.env()
), class = "httr2_response")
return(resp)
}
Loading

0 comments on commit d9bf492

Please sign in to comment.