-
Notifications
You must be signed in to change notification settings - Fork 241
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
units::set_units cannot work with class "difftime" #3012
Comments
Hi @istfer, If we replace
|
Hi @nanu1605 yes I think that would solve it, but also maybe the outermost Alternatively, we could make sure What do others think? For the sake of being practical, you could just go with the change in the |
Hi @istfer have you updated the |
I think this definitely calls for changes inside
Notice that 25 is the correct number of hours, but the resulting difftime object thinks it's 25 days. This happens because ud.convert constructs a new numeric vector containing the converted results and then blindly copies all attributes from the input object, including the now-inaccurate units attribute. I think we definitely do NOT want One option would be for
...but I don't know how closely the difftime and udunits results will align. Another option would be to pass the values as numeric to udunits, but detect when |
@infotroph I think adding the above snippet is a great idea for now. Should I open a PR for it? |
@nanu1605 On further consideration I think we want to have the conversion be done inside the udunits library not
|
@infotroph I changed the function a little. Its working fine, but I am not sure it's the right method or not
|
I think class library(units)
#> udunits database from /usr/local/share/udunits/udunits2.xml
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
days_since_1700 <- as.POSIXct(c("2003-01-01 00:00:00 UTC", "2003-01-01 00:30:00 UTC")) - lubridate::ymd_hm("1700-01-01 00:00")
class(days_since_1700)
#> [1] "difftime"
units(days_since_1700)
#> [1] "days"
days_since_1700 |> as_units() |> set_units("seconds")
#> Units: [s]
#> [1] 9561733200 9561735000 Created on 2023-05-16 with reprex v2.0.2 I think the safest way to go would be with a modified version of what @infotroph suggested here: #3012 (comment) I'll make a quick PR |
Allow `ud_convert()` to work with class "difftime" (fix for #3012)
Bug Description
Recent
udunits2
tounits
change introduced a bug to one of our common met process pipeline. This met2CF.csv line is now throwing an error:To Reproduce
Try the demo run or see:
Proposed solution
We can change class from
difftime
tonumeric
before conversion:or any other solutions are welcome.
The text was updated successfully, but these errors were encountered: