Skip to contents

Reads a CSV or xlsx schedule file produced by write_schedule() (or hand-built in Excel) and returns a validated creel_schedule object ready for use with creel_design().

Usage

read_schedule(path)

Arguments

path

Path to a CSV (.csv) or xlsx (.xlsx, .xls) schedule file. For xlsx files the readxl package must be installed.

Value

A creel_schedule object with columns:

  • date (Date)

  • day_type (character)

  • period_id (integer, if present)

  • p_period (numeric, if present): the probability each worked period was drawn for its day. Every row with a period on a sampled day must carry one in (0, 1]; a missing, non-numeric or out-of-range value is an error, because the period could not be expanded to the day. A file with period_id but no p_period column (written before the column existed) is read as p_period = 1, with a warning, when every sampled day carries the same periods (each was worked every day); if the periods differ between days they were drawn, and it is an error.

  • shift_start, shift_end (character "HH:MM", if present)

  • shift_hours (numeric, if present)

  • day_start (character "HH:MM", if present): when each survey day begins; shift times are read on that clock

  • sampled (logical, if present)

Details

The format is detected from the file extension. All columns are read as text first, then coerce_schedule_columns() applies type coercion – the same logic runs regardless of format so that Excel-reformatted dates and serial numbers are handled consistently.

Examples

sched <- generate_schedule(
  "2024-06-01", "2024-08-31",
  n_periods = 2,
  sampling_rate = c(weekday = 0.3, weekend = 0.6),
  seed = 42
)
tmp <- tempfile(fileext = ".csv")
write_schedule(sched, tmp)
sched2 <- read_schedule(tmp)
inherits(sched2, "creel_schedule")
#> [1] TRUE