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

Error catching: invalid year #7

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

Error catching: invalid year #7

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

Comments

@ran-codes
Copy link

Need error checka nd appropriate CLI error message when year is invalid

 summarise_svi(
+   year = 20133,
+   state = "NJ",
+   geography = 'zcta' )
Error in get(filename) : object 'census_variables_20133' not found
@heli-xu
Copy link
Owner

heli-xu commented Jun 20, 2023

Good point. This ends up being treated differently in get_census_data() vs find_svi().

get_census_data()

year only takes a single year, so multi-year input and a single invalid year will return different errors:

#one invalid year
get_census_data(year = 1234, state = c('PA', 'NJ'), geography = 'county')
Error in `get_census_data()`:
✖ 1234 is not a valid input for `year`.
ℹ Years available for census data retrieval: 2012-2021.

#multi year
get_census_data(year = 2018:2019, state = c('PA', 'NJ'), geography = 'county')
Error in `get_census_data()`:
✖ `year` contains 2 years.
ℹ Data retrieval is performed one year at a time. To retrieve data
  (and compute SVI) for multiple years separately, use `find_svi()`.

find_svi()

year takes single- or multi-year input. For single-year input, error messages rely on get_census_data(), whereas for multi-year input, find_svi() includes its own QC.

#one invalid year
find_svi(year = 1234, state = 'PA', geography = 'county')
Error in `findSVI::get_census_data()` at findSVI/R/find_svi.R:146:6:
✖ 1234 is not a valid input for `year`.
ℹ Years available for census data retrieval: 2012-2021.

#multi year
find_svi(year = c(2019, 1234), state = c('PA','NJ'), geography = 'county')
Error in `find_svi()`:
✖ One or more elements of 2019 and 1234 is not a valid input
  for `year`.
ℹ Years available for census data retrieval: 2012-2021.

Hope this clears things up!

@ran-codes
Copy link
Author

Looks great!

I think one small thingy... may to consider is to add a distinct() call within find_svi() for cases where people accidentally specify repeated combinations for example

find_svi(
  year = c(2013,2013),
  state = rep("NJ",2),
  geography = 'zcta')

other than that I think the issue is resolved

@heli-xu
Copy link
Owner

heli-xu commented Jun 22, 2023

mmm.. if someone put in matching number of repeated year and state, they might actually mean it(?), though I can't see why.
It's also tricky because sometimes there'll be repeated year/state somewhere in the argument but belonging to different pairs, so distinct() might not work directly.
Overall it might be easier for people to remove the repeated part on their end or do another run with modified arguments altogether.

@ran-codes
Copy link
Author

this behavior above is 'feature not a bug'. agreed we should keep it as is.

@heli-xu heli-xu closed this as completed Jun 27, 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