When I run the following code in R I get a strange note (it only appears the first time I run the code in a session):
> library(lubridate)
Attaching package: ‘lubridate’
The following object is masked from ‘package:base’:
date
Warning message:
package ‘lubridate’ was built under R version 3.3.2
> data.frame(i = interval(ymd(20140101), ymd(20160101)))$i %/% years(1)
Note: method with signature ‘Timespan#Timespan’ chosen for function ‘%/%’,
target signature ‘Interval#Period’.
"Interval#ANY", "ANY#Period" would also be valid
[1] 2
I am doubly confused:
This warning will only occur the first time you run it to remind you of that doing integer division has the problem that months or years do not necessarily have the same length in other units like hours or days.
Suppose that we divide the interval 2014--2018 by 2 years, it would not be completely correct to say that the answer is 4 because 2016 is a leap year and has 366 days. So it will be correct if you unit of measure is only years, but it is not strictly correct if you present it as an interval (which may be expressed in years, but also in days, or hours).
There is really no way around the warning either (at least not for integer division), as the warning is always to the point, even if you are dividing interval %/% interval or period %/% period.
But it will only show the first time you run your division, after that it goes silent.
data.frame(i = interval(ymd(20140101), ymd(20160101)))$i %/% years(1)
Note: method with signature ‘Timespan#Timespan’ chosen for function ‘%/%’,
target signature ‘Interval#Period’.
"Interval#ANY", "ANY#Period" would also be valid
[1] 2
data.frame(i = interval(ymd(20140101), ymd(20160101)))$i %/% years(1)
[1] 2
In theory it should be possible to avoid the warning if both sides of the division are represented by as a timespan class. But I have never tried to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With