hrecht / censusapi

R package to retrieve U.S. Census data and metadata via API
https://www.hrecht.com/censusapi/
169 stars 31 forks source link

Ensure cleanly formatted column names are returned #31

Closed hrecht closed 6 years ago

hrecht commented 6 years ago

In rare cases, data are returned with periods in the column names as a result of spaces in the json key. See for example (thanks to Andrew Tran):

fl_sd_pop <-  getCensus(name="acs5", 
                        vintage=2015,
                        vars=c("NAME", "B01003_001E"), 
                        region="school district (unified)",
                        regionin="state:12")

returns a column named fl_sd_pop$school.district..unified.

getCensus should clean up colnames by removing doubled and trailing periods/characters and turning the remaining periods/characters into underscores. The cleaned up column name in this example would be school_district_unified

hrecht commented 6 years ago

This was addressed in https://github.com/hrecht/censusapi/commit/ff2c8e65e4cfe2e6f67160c5e9d33aadaceec16a . Leaving the issue open for more testing before CRAN submission. After fix:

fl_sd_pop <-  getCensus(name="acs5", 
                        vintage=2015,
                        vars=c("NAME", "B01003_001E"), 
                        region="school district (unified)",
                        regionin="state:12")
colnames(fl_sd_pop)
> [1] "NAME"   "state"   "school_district_unified"   "B01003_001E" 
hrecht commented 6 years ago

Closed in v0.3.0