healthyregions / oepsData

An R package for easy access to the Opioid Environment Policy Scan (OEPS) datasets.
Creative Commons Attribution 4.0 International
1 stars 0 forks source link

`state_to_fips()` returns empty character vector for state names or abbreviations #15

Closed ccsarapas closed 1 month ago

ccsarapas commented 1 month ago
library(oepsData)

state_to_fips("IL")
# character(0)

state_to_fips("Illinois")
# character(0)

This causes failures in county_to_fips() and load_oeps() when a name or abbreviation is passed to state.

I think the issue might be that relevant_state <- state == states_id_table$NAME and relevant_state <- state == states_id_table$ABBR should use state_chr (lowercase) rather than state (original passed by user).

mradamcox commented 1 month ago

Thanks for this @ccsarapas. I hope to spend a little time on this package later this week and should be able to address this.

bucketteOfIvy commented 1 month ago

Took a peak at this, and the issue was as @ccsarapas guessed -- the internal states_id_table has all lowercase values, so the lookup in state_to_fips failed when checking against state instead of state_chr. It should be working a bit more smoothly now.

mradamcox commented 1 month ago

@bucketteOfIvy thanks for the fix! Looking at the code it makes sense to me. Closing the ticket now.