countieswithindrivingdistance: Counties within Driving Distance

View source: R/countieswithindrivingdistance.R

countieswithindrivingdistanceR Documentation

Counties within Driving Distance

Description

generate a list of counties within a particular driving distance of a location

Usage

countieswithindrivingdistance(
  centerlocation,
  drivingtime = 90,
  considerationradius = drivingtime * 1.5,
  countymaps = NULL,
  fipscodes = NULL,
  output = c("all", "nearbydf", "mapdata", "hobsonslist", "map"),
  key = Sys.getenv("GOOGLE_MAPS_KEY")
)

Arguments

centerlocation

a character string of a location acting as the center from which you want to measure

drivingtime

numeric value of time, in minutes, that you want to drive

considerationradius

numeric value of distance, in miles, that you want to consider. Limits the number of geocoded counties. Recommended to be much larger than drivingtime, perhaps 50 percent larger, to ensure that all counties are considered.

countymaps

a spatialpolygonsdataframe. If NA, data is downloaded and read from the US Census via getcountymaps().

fipscodes

a data frame of fips codes for all counties with bannerized codes added. If NA, data from the tigris package is modified to work

output

a character vector describing what output you want. Available options include, "nearbydf", "mapdata", "hobsonslist" and "map"

key

a Google Maps user API key

Details

this function is not vectorized–you cannot pass in vector of centerlocations (or more usefully, a vector of centerlocations and a second vector of driving distances). Use lapply() for this.

Value

if more than one output is selected, a list containing values of each. If only one output is selected, the object itself is returned, without being wrapped in a list. Outputs include:

  • "nearbydf" a data frame of nearby counties and their distance to centerlocation

  • "mapdata" a SpaitalPolygonsDataFrame of the nearby counties appropriate for use in a leaflet map

  • "hobsonslist" a character vector ready to paste into a Hobsons filter

  • "map" a pre-generated leaflet map


crazybilly/rmapcounties documentation built on Jan. 4, 2024, 6:32 a.m.