Create a tidy data frame, containing volume and occupancy, for a single date and sensor. Use pull_sensor_ids() to obtain metro sensor IDs.

pull_sensor(
  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 frame containing variables volume, occupancy, sensor, date, time.

Details

Output

A complete year's worth of data for volume or occupancy for one sensor
 usually results in a file that is around ~30-31KB.

Also note that if you assign `pull_sensor()`'s output, the result is returned in-memory,
and there must be sufficient space in-memory to do so.

Missing data

Occupancy *can* be missing while volume data exists and vice versa.
It is unknown how a loop could be monitoring volume and not occupancy.

Filtering

The length, headway, and speed filtering parameters allow filtering of
vehicle observations. This can be useful for vehicle classification
(e.g., filtering by length to separate cars from trucks) or identifying
specific traffic patterns. Filters apply to both volume and occupancy data.

Examples

if (FALSE) { # \dontrun{
# Simple example
library(tc.sensors)
library(purrr)
library(data.table)
loop_data <- pull_sensor(5474, "2025-10-14")

# With filtering - passenger cars only (7-19 feet)
library(tc.sensors)
cars_only <- pull_sensor(5474, "2025-10-14",
  length_ft_min = 7,
  length_ft_max = 19
)

# Mapping example
date_range <- seq(as.Date("2024/01/01"), as.Date("2024/01/02"), by = "days")
loop_data <- map(date_range, ~ pull_sensor(8564, .x))
loops_full <- rbindlist(loop_data)

# Parallel mapping example with furrr
library(furrr)
plan(multisession, workers = parallel::detectCores() - 1)

date_range <- seq(as.Date("2024/01/01"), as.Date("2024/01/02"), by = "days")
loop_data <- future_map(date_range, ~ pull_sensor(8564, .x))
loops_full <- rbindlist(loop_data)
} # }