-
Notifications
You must be signed in to change notification settings - Fork 28
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
The method set_units.mixed_units doesn't preserve a vector's ordering #271
Comments
Thanks for the report. @edzer This regression is worth a patch release. |
submitted 0.7-1... |
Ah, we overlooked these:
|
I can't easily find the rcnst problem in units (happens in dplyr?), but valgrind seems to indicate sth with mixed units. |
The rcnst issue is in dplyr. That check was done with dplyr 1.0.4. The new version 1.0.5 should have solved it, but CRAN has to re-run the check. The valgrind issue is new. Quite strange, because nothing has changed in our C++ side. Let me investigate. |
Ok, it's the same problem we had at exit due to the particular memory management model udunits2 has, which requires us to force weak finalizers before freeing the |
I deal with a lot of identical data coming from different sources, each using different units. The mixed_units class and function are very convenient to harmonize everything but since I upgraded to units v0.7 I have found that applying set_units() to a mixed_units vector now mess up the ordering of the initial vector.
library(units)
#> Warning: package 'units' was built under R version 4.0.4
#> udunits database from H:/HOME/Personal/R/win-library/4.0/units/share/udunits/udunits2.xml
a <- 3001:3010
b <- rep(c('m', 'yard'), 5)
c <- mixed_units(a,b)
c
#> Mixed units: m (5), yard (5)
#> 3001 [m], 3002 [yard], 3003 [m], 3004 [yard], 3005 [m], 3006 [yard], 3007 [m], 3008 [yard], 3009 [m], 3010 [yard]
set_units(c, 'km', mode = "standard")
#> Mixed units: km (10)
#> 3.001 [km], 3.003 [km], 3.005 [km], 3.007 [km], 3.009 [km], 2.745029 [km], 2.746858 [km], 2.748686 [km], 2.750515 [km], 2.752344 [km]
The order of values is not preserved, the old 'm' are at the head of vector and the old 'yard' at the tail
The quick fix I had to use to preserve the sequence:
library(purrr)
set_units(map2_dbl(c,'km', function(x,y) set_units(x,y,mode = 'standard')), 'km', mode = 'standard')
#> Units: [km]
#> [1] 3.001000 2.745029 3.003000 2.746858 3.005000 2.748686 3.007000 2.750515
#> [9] 3.009000 2.752344
The text was updated successfully, but these errors were encountered: