censusr 0.0.3
/We recently pushed an update of our censusr
package to CRAN. censusr
allows R users to download data from the US Census
Bureau's API directly to their workspaces, enabling scripting and powerful analyses.
You can install the latest version of censusr
with:
install.packages("censusr")
See the package vignette on how to setup your API key. Once your API key is in
place, you can query the number of households in Wake County, North Carolina
(GEOID = "37183"
) by vehicles available (B08201_002E
through BO8201_006E
)
like this:
library(censusr)
call_census_api(
paste("B08201_", sprintf("%03d", 2:6), "E", sep = ""),
names = c(0:4), geoids = "37183",
data_source = "acs", year = 2012, period = 5)
## # A tibble: 1 x 6
## geoid `0` `1` `2` `3` `4`
## * <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 37183 15813 111992 149742 47222 16534
This update includes some bug fixes and uses Census' new
https
API protocol. There is also a new function, append_geoid()
to get
the census geography for a latitude/longitude coordinate or an address.
# Define lat/lon as a data frame
us_capitol <- dplyr::data_frame(lat = 38.8899, lon = -77.0091)
# Pass the data frame to `append_geoid` to append a geoid column
append_geoid(us_capitol, 'bg')
## # A tibble: 1 x 3
## lat lon geoid
## <dbl> <dbl> <chr>
## 1 38.8899 -77.0091 110010062021
# Or, define a data frame with the following address columns
airport <- dplyr::data_frame(
street = "700 Catalina Dr", city = "Daytona Beach", state = "FL")
# Pass the data frame to `append_geoid` to append a geoid column in the same way
append_geoid(airport, 'tr')
## # A tibble: 1 x 4
## street city state geoid
## <chr> <chr> <chr> <chr>
## 1 700 Catalina Dr Daytona Beach FL 12127092500