Fetch vehicle length data for a single date and sensor from the Mayfly API. Use pull_sensor_ids() to obtain metro sensor IDs. Vehicle length can be used for vehicle classification (e.g., cars vs. trucks).

pull_sensor_length(
  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 length_ft, sensor, date, hour, min.

Details

Vehicle Classification

Vehicle length filtering enables classification of vehicle types:
- Motorcycles: < 7 feet
- Passenger cars: 7-19 feet
- Small trucks/SUVs: 19-24 feet
- Large trucks: > 24 feet

These are approximate ranges and may vary based on local vehicle mix.

Filtering

Additional filtering by speed and headway allows for more refined traffic
analysis and vehicle classification.

Examples

if (FALSE) { # \dontrun{
library(tc.sensors)
# Simple example
length_data <- pull_sensor_length(5474, "2025-10-14")

# Vehicle classification - passenger cars only
cars_only <- pull_sensor_length(5474, "2025-10-14",
  length_ft_min = 7,
  length_ft_max = 19
)

# Large trucks traveling at highway speeds
trucks_highway <- pull_sensor_length(5474, "2025-10-14",
  length_ft_min = 24,
  speed_mph_min = 55,
  speed_mph_max = 75
)
} # }