You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
get_ethogram <- function(data, x, behaviour, sampling_period = NULL){
if (is.null(sampling_period)){
cli::cli_alert_warning("`sampling_period` not provided.")
sampling_period <- min(diff(dplyr::pull(data, {{x}})))
cli::cli_inform("Sampling period estimated to {sampling_period} using min difference between observations")
}
data <- dplyr::select(data, x = {{x}}, behaviour = {{behaviour}})
etho <- data %>%
dplyr::mutate(run_id = vctrs::vec_identify_runs(behaviour)) %>%
dplyr::group_by(run_id) %>%
dplyr::summarise(behaviour = base::unique(behaviour),
xend = dplyr::last(x) + sampling_period,
x = dplyr::first(x),
duration = xend - x,
.groups = "keep") %>%
dplyr::select(run_id, x, xend, behaviour, duration)
return(etho)
}
Would return something like
get_ethogram(sleep_behavior, aligned_time_sec, sleep)
! `sampling_period` not provided.
Sampling period estimated to 1.99999999999989 using min difference between observations
# A tibble: 294 × 5
# Groups: run_id [294]
run_id x xend behaviour duration
<int> <dbl> <dbl> <chr> <dbl>
1 1 -41.0 1313. Wake 1354
2 2 1313. 1333. NREM 20
3 3 1333. 1349. Wake 16
4 4 1349. 1355. NREM 6
5 5 1355. 1417. Wake 62
6 6 1417. 1451. NREM 34
7 7 1451. 1481. Wake 30
8 8 1481. 1549. NREM 68
9 9 1549. 1593. Wake 44
10 10 1593. 1617. NREM 24
# … with 284 more rows
# ℹ Use `print(n = ...)` to see more rows
The user needs to be cautious with the grouping of the data.frame and how they call each function. It would be great to handle the has_x + has_no_x + ... and everything we do for the plot itself inside one function, but maybe a few functions can simplify things and then have a wrapper ?
The text was updated successfully, but these errors were encountered:
For example
Would return something like
The user needs to be cautious with the grouping of the
data.frame
and how they call each function. It would be great to handle thehas_x
+has_no_x
+ ... and everything we do for the plot itself inside one function, but maybe a few functions can simplify things and then have a wrapper ?The text was updated successfully, but these errors were encountered: