Skip to content

Commit

Permalink
Merge pull request #16 from getwilds/error
Browse files Browse the repository at this point in the history
edited error handling message
  • Loading branch information
realbp authored Feb 7, 2024
2 parents 0681c7d + 4326100 commit 024aad2
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 47 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ Imports:
magrittr,
rlang,
stringr,
testthat,
tibble,
utils
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ importFrom(httr2,request)
importFrom(httr2,resp_body_string)
importFrom(magrittr,"%>%")
importFrom(rlang,":=")
importFrom(rlang,is_na)
importFrom(rlang,sym)
importFrom(stats,setNames)
importFrom(stringr,str_pad)
Expand Down
4 changes: 2 additions & 2 deletions R/handle-age.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ handle_age <- function(age) {

age_code <- age_mapping[age]

if (is.null(age_code)) {
stop("Invalid input")
if (is_na(age_code)) {
stop("Invalid age input, please check the documentation for valid inputs")
}

return(as.character(age_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-alcohol.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ handle_alcohol <- function(alcohol) {

alcohol_code <- alcohol_mapping[alcohol]

if (is.null(alcohol_code)) {
stop("Invalid input")
if (is_na(alcohol_code)) {
stop("Invalid alcohol input, please check the documentation for valid inputs")
}

return(as.character(alcohol_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-cancer.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ handle_cancer <-function(cancer) {

cancer_code <- cancer_mapping[cancer]

if (is.null(cancer_code)) {
stop("Invalid input")
if (is_na(cancer_code)) {
stop("Invalid cancer input, please check the documentation for valid inputs")
}

return(as.character(cancer_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-diet-exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ handle_diet_exercise <- function(diet_exercise) {

diet_exercise_code <- diet_exercise_mapping[diet_exercise]

if (is.null(diet_exercise_code)) {
stop("Invalid input")
if (is_na(diet_exercise_code)) {
stop("Invalid diet excerise input, please check the documentation for valid inputs")
}

return(as.character(diet_exercise_code))
Expand Down
1 change: 0 additions & 1 deletion R/handle-education.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ handle_education <-function(education) {
)

edu_code <- edu_mapping[education]
print(edu_code)

if (is_na(edu_code)) {
stop("Invalid education input, please check the documentation for valid inputs")
Expand Down
4 changes: 2 additions & 2 deletions R/handle-food.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ handle_food <- function(food) {

food_code <- food_mapping[food]

if (is.null(food_code)) {
stop("Invalid input")
if (is_na(food_code)) {
stop("Invalid food input, please check the documentation for valid inputs")
}

return(as.character(food_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-income.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ handle_income <- function(income) {

income_code <- income_mapping[income]

if (is.null(income_code)) {
stop("Invalid input")
if (is_na(income_code)) {
stop("Invalid income input, please check the documentation for valid inputs")
}

return(as.character(income_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-insurance.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ handle_insurance <- function(insurance) {

insurance_code <- insurance_mapping[insurance]

if (is.null(insurance_code)) {
stop("Invalid input")
if (is_na(insurance_code)) {
stop("Invalid insurance input, please check the documentation for valid inputs")
}

return(as.character(insurance_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-mobility.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ handle_mobility <-function(mobility) {

mobility_code <- mobility_mapping[mobility]

if (is.null(mobility_code)) {
stop("Invalid input")
if (is_na(mobility_code)) {
stop("Invalid mobility input, please check the documentation for valid inputs")
}

return(as.character(mobility_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-population.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ handle_population <- function(population) {

population_code <- population_mapping[population]

if (is.null(population_code)) {
stop("Invalid input")
if (is_na(population_code)) {
stop("Invalid population input, please check the documentation for valid inputs")
}

return(as.character(population_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-poverty.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ handle_poverty <- function(poverty) {

poverty_code <- poverty_mapping[poverty]

if (is.null(poverty_code)) {
stop("Invalid input")
if (is_na(poverty_code)) {
stop("Invalid poverty input, please check the documentation for valid inputs")
}

return(as.character(poverty_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-race.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ handle_race <- function(race) {

code <- race_mapping[race]

if (is.null(code)) {
stop("Invalid input")
if (is_na(code)) {
stop("Invalid race input, please check the documentation for valid inputs")
}

return(as.character(code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-risk-datatype.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ handle_datatype <- function(datatype) {

datatype_code <- datatype_mapping[datatype]

if (is.null(datatype_code)) {
stop("Invalid input")
if (is_na(datatype_code)) {
stop("Invalid datatype input, please check the documentation for valid inputs")
}

return(as.character(datatype_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-screening.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ handle_screening <- function(screening) {

screening_code <- screening_mapping[screening]

if (is.null(screening_code)) {
stop("Invalid input")
if (is_na(screening_code)) {
stop("Invalid screening input, please check the documentation for valid inputs")
}

return(as.character(screening_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-sex.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ handle_sex <- function(sex) {

sex_code <- sex_mapping[sex]

if (is.null(sex_code)) {
stop("Invalid input")
if (is_na(sex_code)) {
stop("Invalid sex input, please check the documentation for valid inputs")
}

return(as.character(sex_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-smoking.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ handle_smoking <- function(smoking) {

smoking_code <- smoking_mapping[smoking]

if (is.null(smoking_code)) {
stop("Invalid input")
if (is_na(smoking_code)) {
stop("Invalid smoking input, please check the documentation for valid inputs")
}

return(as.character(smoking_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-stage.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ handle_stage <-function(stage) {

stage_code <- stage_mapping[stage]

if (is.null(stage_code)) {
stop("Invalid input")
if (is_na(stage_code)) {
stop("Invalid stage input, please check the documentation for valid inputs")
}

return(as.character(stage_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-svi.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ handle_svi <- function(svi) {

svi_code <- svi_mapping[svi]

if (is.null(svi_code)) {
stop("Invalid input")
if (is_na(svi_code)) {
stop("Invalid svi input, please check the documentation for valid inputs")
}

return(as.character(svi_code))
Expand Down
8 changes: 2 additions & 6 deletions R/handle-vaccine.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ handle_vaccine <- function(vaccine) {

vaccine_code <- vaccine_mapping[vaccine]

if (is.null(vaccine_code)) {
stop("Invalid input")
if (is_na(vaccine_code)) {
stop("Invalid vaccine input, please check the documentation for valid inputs")
}

return(as.character(vaccine_code))
}

handle_vaccine("percent who received 3+ doses of hpv vaccine, ages 13-17")

6 changes: 4 additions & 2 deletions R/handle-whealth.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' @param whealth 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+"
#'
#' @importFrom rlang is_na
#'
#' @returns A string for its respective Women's Health Value
#'
Expand All @@ -27,8 +29,8 @@ handle_whealth <- function(whealth) {

whealth_code <- whealth_mapping[whealth]

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

return(as.character(whealth_code))
Expand Down
4 changes: 2 additions & 2 deletions R/handle-year.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ handle_year <-function(year) {

year_code <- year_mapping[year]

if (is.null(year_code)) {
stop("Invalid input")
if (is_na(year_mapping)) {
stop("Invalid year input, please check the documentation for valid inputs")
}

return(as.character(year_code))
Expand Down

0 comments on commit 024aad2

Please sign in to comment.