Skip to content
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

unit conversion with rbind (on data.frames) #232

Closed
dleutnant opened this issue Mar 24, 2020 · 1 comment
Closed

unit conversion with rbind (on data.frames) #232

dleutnant opened this issue Mar 24, 2020 · 1 comment
Labels

Comments

@dleutnant
Copy link

Hi,
I just came across the following issue, in which the automatic unit conversion does not apply.
The reprex aims to rbind two data.frames which share the same column 'dt' of class 'units'. The unit however differs and the first one is used during rbind. Most probably this is rather a "rbind"-related issue but I thought it is worth sharing it here...

library(units)
#> udunits system database from /usr/local/share/udunits

# dummy data
h <- data.frame(dt = set_units(24, "h"))
min <- data.frame(dt = set_units(1440, "min"))

# binding both data.frames works, but silently gives wrong unit conversion results
# issue: first unit dominates the other 

# ... here: hour
rbind(h, min)
#>         dt
#> 1   24 [h]
#> 2 1440 [h]
# ... here: mins
rbind(min, h)
#>           dt
#> 1 1440 [min]
#> 2   24 [min]

Created on 2020-03-24 by the reprex package (v0.3.0)

@Enchufa2 Enchufa2 added the bug label Mar 26, 2020
@Enchufa2
Copy link
Member

The issue we have here is that

x <- set_units(24, h)
x[2] <- set_units(1440, min)
x
#> Units: [h]
#> [1] 24 1440

And, more generally,

x[2] <- set_units(3, m)
x
#> Units: [h]
#> [1] 24 3

@edzer edzer closed this as completed in 6ea40d9 Mar 26, 2020
edzer added a commit that referenced this issue Mar 26, 2020
close #232: fix replacement of parts of units
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants