Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid state inputs: improved CLI error mesage #4

Closed
ran-codes opened this issue Jun 12, 2023 · 3 comments
Closed

Invalid state inputs: improved CLI error mesage #4

ran-codes opened this issue Jun 12, 2023 · 3 comments

Comments

@ran-codes
Copy link

If users input a incorrect state it currently just returns a unspecified bug

summarise_svi(
+   year = 2015,
+   state = "ghfj",
+   geography = 'zcta' )
Getting data from the 2011-2015 5-year ACS
Fetching data by table type ("B/C", "S", "DP") and combining the result.
Error in `map()`:
i In index: 1.
Caused by error in `rate_sleep()`:
! Request failed after 3 attempts.
Run `rlang::last_trace()` to see where the error occurred.

There probably needs to be a QC check within summarise_svi() or get_data() that checks if the state specified is valid (one of the accepted 2 letter abbreviations. If not then an appropriate error message via CLI is required. For example above,

a potentially message could be:

vec__invalid_state = ....
vec__invalid_state  |> walk(~cli_alert_danger(".x is not a valid state"))
@heli-xu
Copy link
Owner

heli-xu commented Jun 20, 2023

A QC check for valid state/year is added in get_census_data() and in turn also used for find_svi(). Error message is updated and a reference table state_valid is added to the package for valid input in the form of full name/abbreviation/FIPS code.

For the same example above, this is what it looks like now:

find_svi(
+     year = 2015,
+     state = "ghfj",
+     geography = 'zcta' )
Error in `findSVI::get_census_data()` at findSVI/R/find_svi.R:118:6:
✖ One or more elements of ghfj is not a valid input for
  `state`.
ℹ Use `state_valid` for a table of valid input (besides 'US'). Note
  state full names/abbreviations are characters; FIPS codes are
  numbers.
Run `rlang::last_error()` to see where the error occurred.

If using FIPS code:

find_svi(2015, state = 99, geography = "county")
Error in `findSVI::get_census_data()` at findSVI/R/find_svi.R:118:6:
✖ One or more elements of 99 is not a valid input for `state`.
ℹ Use `state_valid` for a table of valid input (besides 'US'). Note
  state full names/abbreviations are characters; FIPS codes are
  numbers.
Run `rlang::last_error()` to see where the error occurred.

Hopefully it looks clearer?

@heli-xu
Copy link
Owner

heli-xu commented Jun 20, 2023

I realized if find_svi() QC relies on get_census_data(), it's evaluated later than ideal. Especially when the first pair of year-state is valid, the error message does not show up until the first entry is done running.

find_svi(year = 2017:2018, state = c(01, 98), geography = "zcta")
Getting data from the 2013-2017 5-year ACS
Fetching data by table type ("B/C", "S", "DP") and combining the result.
✔ Finished retrieving census data for 2017 1
Error in `map2()`:
ℹ In index: 2.
Caused by error in `findSVI::get_census_data()` at findSVI/R/find_svi.R:189:8:
✖ One or more elements of 98 is not a valid input for `state`.
ℹ Use `state_valid` for a table of valid input (besides 'US'). Note
  state full names/abbreviations are characters; FIPS codes are
  numbers.

So a separate set of QC is added to find_svi(), and QC will be done first thing.

find_svi(year = 2017:2018, state = c(01, 98), geography = "zcta")
Error in `find_svi()`:
✖ One or more elements of 1 and 98 is not a valid input for
  `state`.
ℹ Use `state_valid` for a table of valid input (besides 'US'). Note
  state full names/abbreviations are characters; FIPS codes are
  numbers.

@ran-codes
Copy link
Author

QC looks great! Really like the CLI messages... so user friendly!

@heli-xu heli-xu closed this as completed Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants