Description Usage Arguments Value Examples
View source: R/loop_sensor_functions.R
Create a tidy dataframe, containing volume and occupancy, for a single date and sensor. Use 'pull_sensor_ids' to obtain metro sensor IDs.
1 | pull_sensor(sensor, pull_date, date_fmt = c("ymd", "dmy", "mdy"))
|
sensor |
an object of class integer or string which indicates the sensor ID. See documentation for 'pull_sensor_ids' to obtain metro sensor IDs.unction |
pull_date |
an object of class integer or string which indicates the date of data to pull. Can be in mdy, ymd, or dmy format, but format must be specified in the date_fmt argument. A vector of dates is accepted when used in tandem with the 'purrr::pmap()' function. |
date_fmt |
an object of class string which indicates the format of the 'pull_date' argument. |
dataframe containing variables volume, occupancy, sensor, date, time. Note that occupancy *can* be missing while volume data exists and vice versa. It is unknown how a loop could be monitoring volume and not occupancy. Also note that if you assign the output of pull_loops, the result is returned in-memory, and there must be sufficient space in-memory to do so.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # Simple example
loop_data <- pull_sensor(5474, "20190101", "ymd")
date_range <- c(20190101:20190201)
loop_data <- pmap(list(8564, date_range, "ymd"), pull_sensor)
loops_full <- rbindlist(loop_data)
# Parallel mapping example; takes longer if only pulling one or two days because libraries have to be copied to each core
library(parallel)
cl <- makeCluster(detectCores() - 1) # Leaving one core unused
params <- list(8564, date_range, "ymd")
clusterSetRNGStream(cl, 1)
loop_data <- params %>%
lift(clusterMap, cl = cl)(fun = pull_sensor)
stopCluster(cl)
loops_full <- rbindlist(loop_data)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.