This function splits RR intervals into the orthostatic test phases (laying, transition, and standing) based on specified time thresholds.
split_rr_phases(
rr_intervals,
session_info,
laying_time = 180,
transition_time = 20,
standing_time = 180,
centered_transition = TRUE
)A data frame containing RR interval data. Must include
a column named time. The function will add an elapsed_time column
and a phase column.
A list containing session information. Must include a
numeric element named duration representing the total duration of the
recording (in the same units as laying_time, transition_time, and
standing_time).
Numeric. The duration of the laying phase (e.g., in seconds). Must be non-negative.
Numeric. The duration of the transition phase (e.g., in seconds). Must be non-negative.
Numeric. The duration of the standing phase (e.g., in seconds). Must be non-negative.
Indicates if the transition time should be split into laying and standig times. FALSE, if transition time is only taken from the laying phase.
A data frame with the same data as rr_intervals, but with two
added columns:
The cumulative time from the start of the recording.
A character string indicating the phase: "laying", "transition", or "standing".
The sum of laying_time and standing_time cannot exceed
session_info$duration. If rr_intervals is an empty data frame, a
warning is issued, and an empty data frame with a phase column is
returned.
# Example with valid inputs
rr_data <- data.frame(time = 1:100)
session_data <- list(duration = 100)
result <- split_rr_phases(rr_data, session_data, 30, 20, 50)
head(result)
#> # A tibble: 6 × 3
#> time elapsed_time phase
#> <int> <dbl> <chr>
#> 1 1 1 laying
#> 2 2 2 laying
#> 3 3 3 laying
#> 4 4 4 laying
#> 5 5 5 laying
#> 6 6 6 laying
# Example with an empty rr_intervals data frame
rr_empty <- data.frame(time = numeric())
session_data <- list(duration = 60)
result_empty <- split_rr_phases(rr_empty, session_data, 20, 10, 30)
#> Warning: rr_intervals is an empty tibble. An empty tibble with phase
#> column will be returned.
print(result_empty)
#> # A tibble: 0 × 2
#> # ℹ 2 variables: time <dbl>, phase <chr>
if (FALSE) { # \dontrun{
# Example with invalid input (sum of times exceeds duration)
rr_data <- data.frame(time = 1:100)
session_data <- list(duration = 100)
# This will throw an error
result_error <- split_rr_phases(rr_data, session_data, 50, 60, 70)
} # }