Skip to content

Commit

Permalink
Bugfix for sleep.int2Brown when intervals prior to sleep are less tha…
Browse files Browse the repository at this point in the history
…n the specified duration
  • Loading branch information
JZauner committed Oct 25, 2023
1 parent 1e56d19 commit f103b89
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions R/sleepint2Brown.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' `evening` and `day` intervals. The `evening.length` is the time between `day`
#' and `night`. The result can be used as input for [interval2state()] and might
#' be used subsequently with [Brown2reference()].
#'
#' The function will filter out any non-sleep intervals that are shorter than the specified `evening.length`. This prevents problematic behaviour when the `evening.length` is longer than the `wake` intervals or, e.g., when the first state is sleep after midnight and there is a prior `NA` interval from midnight till sleep. This behavior might, however, result in problematic results for specialized experimental setups with ultra short wake/sleep cycles. The `sleep.int2Brown()` function would not be applicable in those cases anyways.
#'
#' @param dataset A dataset with sleep/wake intervals.
#' @param Interval.colname The name of the column with the intervals. Defaults to `Interval`.
Expand Down Expand Up @@ -75,6 +77,14 @@ sleep.int2Brown <- function(dataset,

# Manipulation ----------------------------------------------------------

#filter out intervals other than "sleep" and are shorter than the evening length
dataset <-
dataset %>%
dplyr::filter(
!({{ Sleep.colname }} != sleep.state &
lubridate::int_length({{ Interval.colname }}) < evening.length)
)

#get intervals that are of type "sleep" and create start and endpoints for a new interval "evening"
evening.data <- dataset %>%
dplyr::filter({{ Sleep.colname }} == sleep.state) %>%
Expand Down
Loading

0 comments on commit f103b89

Please sign in to comment.