Fetch headway (time between vehicles in seconds) data for a single date and sensor from the Mayfly API. Use pull_sensor_ids() to obtain metro sensor IDs. At this time very few sensors in the metro area report headway data. Sensor 6206 is one example.

pull_sensor_headway(
  sensor,
  pull_date,
  fill_gaps = TRUE,
  length_ft_min = NULL,
  length_ft_max = NULL,
  headway_sec_min = NULL,
  headway_sec_max = NULL,
  speed_mph_min = NULL,
  speed_mph_max = NULL,
  district = "metro",
  .quiet = TRUE
)

Arguments

sensor

character, the sensor ID. See pull_sensor_ids() to obtain metro sensor IDs.

pull_date

character, the date of data to pull. Accepts either "YYYY-MM-DD" or "YYYYMMDD" format.

fill_gaps

logical, whether to fill gaps in the time series with NA values. Default is TRUE

length_ft_min

numeric, minimum vehicle length in feet for filtering. Optional. Default is NULL.

length_ft_max

numeric, maximum vehicle length in feet for filtering (non-inclusive). Optional. Default is NULL.

headway_sec_min

numeric, minimum headway in seconds for filtering. Optional. Default is NULL.

headway_sec_max

numeric, maximum headway in seconds for filtering (non-inclusive). Optional. Default is NULL.

speed_mph_min

numeric, minimum speed in mph for filtering. Optional. Default is NULL.

speed_mph_max

numeric, maximum speed in mph for filtering (non-inclusive). Optional. Default is NULL.

district

character, MnDOT district code. Default is "metro". Use mayfly_get_districts() to see available districts.

.quiet

logical, whether to suppress error messages. Default TRUE

Value

data.table containing variables headway, sensor, date, hour, min.

Details

Filtering

The filtering parameters allow filtering of vehicle observations based on
headway (time between vehicles), vehicle length, and speed. This can be useful
for identifying specific traffic patterns or filtering outliers.

Examples

if (FALSE) { # \dontrun{
library(tc.sensors)
# Simple example
headway_data <- pull_sensor_headway(6206, "2025-10-14")

# With filtering - passenger cars with 2-10 second headway
filtered_data <- pull_sensor_headway(6206, "2025-10-14",
  headway_sec_min = 2,
  headway_sec_max = 10,
  length_ft_min = 10,
  length_ft_max = 20
)
} # }