by_time: Specify interval boundaries by time, label, lap, or sample

View source: R/extract_interval_helpers.R

by_timeR Documentation

Specify interval boundaries by time, label, lap, or sample

Description

Helper functions to define interval start or end boundaries for extract_intervals().

Usage

by_time(...)

by_label(...)

by_lap(...)

by_sample(...)

Arguments

...

Specify start or end boundaries.

by_time(...)

Numeric time values in units of time_channel.

by_label(...)

Character strings to match in event_channel. All matching occurrences are returned.

by_lap(...)

Integer lap numbers to match in event_channel. For start, resolves to the first sample of each lap. For end, resolves to the last sample.

by_sample(...)

Integer sample indices (row numbers).

Details

These helpers can be used explicitly for arguments start/end, or raw values can be passed directly:

  • Numeric -> by_time()

  • Character -> by_label(),

  • Explicit integer (e.g. 2L) -> by_lap().

  • Use by_sample() explicitly for sample indices.

Value

An object of class "mnirs_interval" for use with the start and end arguments of extract_intervals().

Examples

## read example data
data <- read_mnirs(
    example_mnirs("train.red"),
    nirs_channels = c(
        smo2_left = "SmO2 unfiltered",
        smo2_right = "SmO2 unfiltered"
    ),
    time_channel = c(time = "Timestamp (seconds passed)"),
    event_channel = c(lap = "Lap/Event"),
    zero_time = TRUE,
    verbose = FALSE
)

## start and end by time
extract_intervals(data, start = by_time(66), end = by_time(357))

## start by lap
extract_intervals(data, start = by_lap(2, 4), span = 0)

## introduce event_channel with "start" string
data$event <- NA_character_
data$event[1000] <- "start"
data <- create_mnirs_data(data, event_channel = "event")

## start by label, end by time
extract_intervals(data, start = by_label("start"), end = by_time(1500))

## multiple intervals by sample index
extract_intervals(data, start = by_sample(1000, 1500), end = by_sample(2000, 2600))


mnirs documentation built on May 15, 2026, 9:07 a.m.