-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow measurement units via units package? #201
Comments
Minor MRE fix: to create a tsibble, the library (tsibble)
library (units)
#> udunits system database from /usr/share/xml/udunits
daily <- set_units (1:100, "day")
class(daily)
#> [1] "units"
x <- tsibble (day = daily, index = day)
#> Error: Unsupported index type: units Created on 2020-06-25 by the reprex package (v0.3.0) |
Are you looking for relative days as index instead of absolute dates? I'd suggest to use library(tsibble)
daily <- hms::hms(day = 1:100)
tsibble (day = daily, index = day)
#> # A tsibble: 100 x 1 [24h]
#> day
#> <time>
#> 1 24:00
#> 2 48:00
#> 3 72:00
#> 4 96:00
#> 5 120:00
#> 6 144:00
#> 7 168:00
#> 8 192:00
#> 9 216:00
#> 10 240:00
#> # … with 90 more rows Created on 2020-06-26 by the reprex package (v0.3.0) Tsibble supports commonly-used time classes. It's up to the package developer to implement custom index classes and their associated intervals for tsibble in the package. |
Thanks @earowang, but the problem is that the straightforward ways to implement intervals do not work: library (tsibble)
library (units)
#> udunits system database from /usr/share/udunits
daily <- set_units (1:100, "day")
x <- tsibble (day = daily, index = day)
#> Error: Unsupported index type: units
library (lubridate)
daily <- days (1:100)
x <- tsibble (day = daily, index = day)
#> Error in vec_proxy_period(x): trying to get slot "year" from an object (class "Period") that is not an S4 object Created on 2020-06-26 by the reprex package (v0.3.0) The only standard units which seem acceptable are absolute ones ( |
The library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
library(tsibble)
#>
#> Attaching package: 'tsibble'
#> The following object is masked from 'package:lubridate':
#>
#> interval
daily <- days(1:100)
tsibble(day = daily, index = day)
#> # A tsibble: 100 x 1 [1D]
#> day
#> <Period>
#> 1 1d 0H 0M 0S
#> 2 2d 0H 0M 0S
#> 3 3d 0H 0M 0S
#> 4 4d 0H 0M 0S
#> 5 5d 0H 0M 0S
#> 6 6d 0H 0M 0S
#> 7 7d 0H 0M 0S
#> 8 8d 0H 0M 0S
#> 9 9d 0H 0M 0S
#> 10 10d 0H 0M 0S
#> # … with 90 more rows Created on 2020-06-26 by the reprex package (v0.3.0) |
That would definitely ease the adoption by people from the modelling communities who use udunits2. Note however that units and calendars have a difficult relationship, here you will read: "CAUTION: The timestamp-unit was created to be analogous to, for example, the degree celsius—but for the time dimension. I've come to believe, however, that creating such a unit was a mistake, primarily because users try to use the unit in ways for which it was not designed (such as converting dates in a calendar whose year is exactly 365 days long). Such activities are much better handled by a dedicated calendar package. Please be careful about using timestamp-units." illustrated by > library(units)
udunits system database from /usr/share/xml/udunits
> set_units(set_units(1, "year"), "days")
365.2422 [d] R's native time/date classes ( |
This
reprex
illustrates the problem:Created on 2020-06-25 by the reprex package (v0.3.0)
With due acknowledgement of your statement in #134 that
there is nevertheless a difference in internal representations within software. In this case, it may be considered important to retain explicit specifications of measurement units, here via the
units
package. This is arguably the only way to put an absolute scale on interval data which have no fixed time scale, and that is surely an important thing to be able to do?The text was updated successfully, but these errors were encountered: