% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/extract_interval_helpers.R
\name{by_time}
\alias{by_time}
\alias{by_label}
\alias{by_lap}
\alias{by_sample}
\title{Specify interval boundaries by time, label, lap, or sample}
\usage{
by_time(...)

by_label(...)

by_lap(...)

by_sample(...)
}
\arguments{
\item{...}{Specify start or end boundaries.
\describe{
\item{\code{by_time(...)}}{Numeric time values in units of \code{time_channel}.}
\item{\code{by_label(...)}}{Character strings to match in \code{event_channel}.
All matching occurrences are returned.}
\item{\code{by_lap(...)}}{Integer lap numbers to match in \code{event_channel}.
For \code{start}, resolves to the first sample of each lap. For \code{end},
resolves to the last sample.}
\item{\code{by_sample(...)}}{Integer sample indices (row numbers).}
}}
}
\value{
An object of class \code{"mnirs_interval"} for use with the \code{start}
and \code{end} arguments of \code{\link[=extract_intervals]{extract_intervals()}}.
}
\description{
Helper functions to define interval start or end boundaries for
\code{\link[=extract_intervals]{extract_intervals()}}.
}
\details{
These helpers can be used explicitly for arguments \code{start}/\code{end}, or raw
values can be passed directly:
\itemize{
\item Numeric -> \code{\link[=by_time]{by_time()}}
\item Character -> \code{\link[=by_label]{by_label()}},
\item Explicit integer (e.g. \code{2L}) -> \code{\link[=by_lap]{by_lap()}}.
\item Use \code{\link[=by_sample]{by_sample()}} explicitly for sample indices.
}
}
\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))

}
