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, .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. Needs to be in "YYYY-MM-DD" format.

fill_gaps

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

.quiet

logical, whether to hide messages. Default is 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.

Approximate time to pull one sensor's and one extension's
 ("v" or "c" for volume or occupancy, respectively) data across
  a year on a Mac is 1.33 minutes.

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.

See also

Other loop sensor functions: pull_configuration(), pull_sensor_ids()

Examples

if (FALSE) {
# Simple example
loop_data <- pull_sensor(5474, "2018-10-14")

# Mapping example
date_range <- seq(as.Date("2019/01/01"), as.Date("2019/01/02"), by = "days")
loop_data <- pmap(list(8564, date_range), pull_sensor)
loops_full <- rbindlist(loop_data)

# Parallel mapping example
## takes longer if only pulling 1-2 days because libraries are copied to each core
library(parallel)
cl <- makeCluster(detectCores() - 1) # Leaving one core unused
params <- list(8564, date_range)

clusterSetRNGStream(cl, 1)
loop_data <- params %>%
  lift(clusterMap, cl = cl)(fun = pull_sensor)
stopCluster(cl)

loops_full <- rbindlist(loop_data)
}