Reduces a pr_dataset to one row per trial: the chosen metadata fields
plus n_frames and duration_s. This is the study design as a table —
the object you count, cross-tabulate, and assert against with
pr_assert_cohort().
Arguments
- dataset
A pr_dataset object, or a list of pr_trial objects.
- fields
Character vector of metadata field names to include, in the order given.
NULL(default) auto-detects: every metadata field that holds a single value in every trial, dropping fields that are missing (NA) throughout — which removes the emptypr_trialdefaults such asnotes. Fields namedn_framesorduration_sare dropped in auto mode and rejected when named explicitly, because both columns are recomputed from the trial itself.
Value
A tibble::tibble with one row per trial and columns
fields, n_frames (integer) and duration_s (numeric).
Details
duration_s is the trial's duration field, i.e.
diff(range(time)), so a 23432-frame recording at 50 Hz gives
468.62 s (not 468.64 s).
See also
Other cohort functions:
pr_assert_cohort(),
pr_dataset_filter(),
pr_validate_dataset()
Examples
layout <- pr_layout_mat("16")
mk <- function(id, mode, n) {
pr_trial(
matrix(1, n, layout$n_sensors),
time = seq(0, (n - 1) / 50, by = 1 / 50),
layout = layout,
metadata = list(ID = id, Mode = mode)
)
}
ds <- pr_dataset(list(mk("ID001", "MS", 4), mk("ID002", "MH", 6)))
pr_design_table(ds, fields = c("ID", "Mode"))
#> # A tibble: 2 × 4
#> ID Mode n_frames duration_s
#> <chr> <chr> <int> <dbl>
#> 1 ID001 MS 4 0.06
#> 2 ID002 MH 6 0.1