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
I found a problem with the resolution function. I expected it to fail on difftime objects uniformly but it does not. This is related to the scales package:
Here is the code to reproduce the bug:
Error
Getting errors with resolution if the object is a difftime (hms) object and there is not a zero in the range.
In my case that means if midnight 00:00:00 is included as an hms value, I get no error, but do otherwise.
Load up Libraries
library(lubridate)
#> #> Attaching package: 'lubridate'#> The following objects are masked from 'package:base':#> #> date, intersect, setdiff, union
library(dplyr)
#> #> Attaching package: 'dplyr'#> The following objects are masked from 'package:stats':#> #> filter, lag#> The following objects are masked from 'package:base':#> #> intersect, setdiff, setequal, union
library(hms)
#> #> Attaching package: 'hms'#> The following object is masked from 'package:lubridate':#> #> hms
library(ggplot2)
Set a Time Near midnight for demonstration purpuoses
The issue doesn’t exist if midnight is somewhere in the time data, so we can set the data near there.
All the rest fail for POSIXt as that if is never satisfied:
resolution(c(the_time, the_time+1))
#> Error in Math.POSIXt(x): 'abs' not defined for "POSIXt" objects
resolution(c(the_time, the_time+60*60*25))
#> Error in Math.POSIXt(x): 'abs' not defined for "POSIXt" objects
Non-identical data that does not cross midnight
Create a sequence that does not cross midnight (aka range has a 0), still error.
resolution(as_hms(seq(the_time, the_time+1, by=1)))
#> Error in `/.difftime`((x[1] - x[2]), m): second argument of / cannot be a "difftime" object
I found a problem with the
resolution
function. I expected it to fail ondifftime
objects uniformly but it does not. This is related to thescales
package:Here is the code to reproduce the bug:
Error
Getting errors with
resolution
if the object is adifftime
(hms
) object and there is not a zero in the range.In my case that means if midnight
00:00:00
is included as anhms
value, I get no error, but do otherwise.Load up Libraries
Set a Time Near midnight for demonstration purpuoses
The issue doesn’t exist if midnight is somewhere in the time data, so we can set the data near there.
Passing in a vector with 1 unique POSIXt value
If we pass in the
the_time
or duplicate copies of it, we get a resolution of 1 second.This is somewhat expected due to
ggplot2/R/utilities-resolution.R
Line 23 in ad97679
will call
scales::zero_range
and the range will be 0 since it’s willexit at https://github.com/r-lib/scales/blob/6e5e4c352b36b0903ebcc484264e2e741cd93922/R/bounds.R#L377.
POSIXt fails generally
All the rest fail for POSIXt as that
if
is never satisfied:Non-identical data that does not cross midnight
Create a sequence that does not cross midnight (aka range has a 0), still error.
The error happens at https://github.com/r-lib/scales/blob/6e5e4c352b36b0903ebcc484264e2e741cd93922/R/bounds.R#L397 and
m
in this case is adifftime
object.Non-identical data that does cross midnight
Create a sequence that crosses midnight, range has a
0
in there, so no error.The error is “resolved” because https://github.com/r-lib/scales/blob/6e5e4c352b36b0903ebcc484264e2e741cd93922/R/bounds.R#L391 exits with
FALSE
.Simpler Example
Much simpler example (but doesn’t show why resolution affected).
This is due to 2 different ranges
Created on 2024-10-11 with reprex v2.1.1
Session info
The text was updated successfully, but these errors were encountered: