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
Hi Marta,
Please see the following reproducible example highlighting some problems we are experiencing with the package. As the function midnight_to_midnight() produces some unexpected results, the rest of the package (e.x. activity_stats()) seems broken as well.
The error seems to originate with the lubridate function ymd_hms, which fails to parse date-times at midnight, though it does parse character vectors at midnight. A potential solution would be to convert the user input to a character vector before re-converting to date-time. I've also "hacked" another solution in which I add one second to each date time, but I am not yet sure if that works for higher-level arc tools functions like activity_stats().
devtools::install_github("martakarass/arctools")
#install.packages("arctools")
library(arctools)
library(lubridate)
# generate a time vector 6am to 6pm next day
start.time <- ymd_hms("2024-02-07 06:00:00 UTC")
acc_ts <- start.time + minutes(0:1439)
class(acc_ts)
# Result is "POSIXct" "POSIXt"
acc <- rnorm(length(acc_ts))
ts_mtm <- midnight_to_midnight(acc = acc_ts, acc_ts = acc_ts)
# Warning message:
# 1 failed to parse.
# check that the length is the desired output
length(acc_ts) #1440
length(ts_mtm) #4320
# in addition to the parsing error, the mtm function adds 1 extra day (1440 minutes)
# at the end
# the error appears to happen when midnight_to_midnight calls lubridate::ymd_hms
acc_ts2 <- lubridate::ymd_hms(acc_ts)
# print original time stamps around the problematic one
acc_ts[(which(is.na(acc_ts2))-2):(which(is.na(acc_ts2))+2)]
################################################################################
# a "hack" solution: adding 1 second to date times
acc_ts <- start.time + minutes(0:1439) + seconds(1)
ts_mtm <- midnight_to_midnight(acc = acc_ts, acc_ts = acc_ts)
# no warning
# check that the length is the desired output
length(acc_ts) #1440
length(ts_mtm) #2880
Hi Marta,
Please see the following reproducible example highlighting some problems we are experiencing with the package. As the function
midnight_to_midnight()
produces some unexpected results, the rest of the package (e.x.activity_stats()
) seems broken as well.The error seems to originate with the lubridate function
ymd_hms
, which fails to parse date-times at midnight, though it does parse character vectors at midnight. A potential solution would be to convert the user input to a character vector before re-converting to date-time. I've also "hacked" another solution in which I add one second to each date time, but I am not yet sure if that works for higher-level arc tools functions likeactivity_stats()
.Some extra notes on
ymd_hms
:The issue has been noted here: tidyverse/lubridate#1124.
Essentially,
ymd_hms
only "works" for times at midnight which are coded as a character vector, not a date-time. Here is an illustration:The text was updated successfully, but these errors were encountered: