arctools's People
arctools's Issues
Issue with midnight_to_midnight(): cascading effects of how lubridate::ymd_hms() handles midnight.
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
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:
ymd_hms("2024-02-08 00:00:00 UTC")
# "2024-02-08 UTC", works
ymd_hms(ymd_hms("2024-02-08 00:00:00 UTC"))
# fails
ymd_hms("2024-02-08 00:01:00 UTC")
# "2024-02-08 00:01:00 UTC", works
ymd_hms(ymd_hms("2024-02-08 00:01:00 UTC"))
# "2024-02-08 00:01:00 UTC", works
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.