-
Notifications
You must be signed in to change notification settings - Fork 991
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
melting integer64 columns together with other classes leads to wrong results #3087
Comments
The warning mentions type, not class. If you look at Btw, if you change the order of the columns, the results change:
I guess only the first columns attributes get carried over. Similar with...
|
I figured out that the problem is not suppressPackageStartupMessages(library(magrittr))
#> Warning: package 'magrittr' was built under R version 3.5.1
suppressPackageStartupMessages(library(bit64))
tibble::tibble(key.var = "A",
col_int = 2147483647L,
col_num = 2147483647,
col_int64 = 2147483648) %>%
dplyr::mutate(col_int64 = as.integer64(col_int64)) %>%
tidyr::gather(key = "variable", value = "value",
-key.var)
#> Warning: package 'bindrcpp' was built under R version 3.5.1
#> Warning: attributes are not identical across measure variables;
#> they will be dropped
#> # A tibble: 3 x 3
#> key.var variable value
#> <chr> <chr> <dbl>
#> 1 A col_int 2.15e+ 9
#> 2 A col_num 2.15e+ 9
#> 3 A col_int64 1.06e-314 Created on 2018-10-02 by the reprex package (v0.2.0). So is it a |
I don't follow. The message you quoted is...
You can inspect what the warning is about, like...
This is similar to the (silent) behavior you see with |
Thanks. Now I understand the issue. One important difference between the |
Hm, yeah, except with some workarounds, like...
|
So it's no bug? Rather an inconvenience? If so, my takeaway would be to convert all columns to be melted / gathered to the correct single type before using |
I don't think it's a bug, but maybe there could be a verbose message or warning when attributes are found in measure columns. Anyway, I think you could leave the issue open if you want more feedback. |
I think this may be the same or a closely related issue:
|
@anwjones Without data.table, your result is the same...
To apply max to the vector instead of the table, you could do either of these...
Hope it's helpful |
I see your solution as a work around rather than "its not a bug". After all a data.frame doesn't show this behavior.
|
@anwjones Sorry, I wasn't clear. Look at:
Data.table behaves like drop=FALSE here. The faq
|
Okay - last comment, then I'll go away. So why do the integer column and the integer64 column behave differently? Is this really the intended behavior ? I can understand NA as a result, but a numeric result which is not the maximum of anything in the data.table has to be wrong ;-( |
@anwjones I can't find a reference for it, but it seems to be that
So they behave differently because integer is an atomic type, while integer64 is an invented type built on top of the atomic type "numeric". If you ask on Stack Overflow, someone would probably know the full explanation. Unless it's a package problem or feature request, I guess we'd probably better stop commenting here, yeah. |
@franknarf1 is this indeed the same as OP's issue? wondering whether to close as being |
@MichaelChirico No; different problem. OP's issue is that melt carries over attributes (from #702) only looking at the first measure variable / column. I don't know if there's a good alternative to that behavior that's worth doing, though maybe there could be a message/warning when attributes are ignored. |
I think I found a bug in
melt.data.table()
. I want to melt several columns of classinteger
andinteger64
. When I melt these columns into a single one, the values from the formerinteger64
columns show weird values.I extended the MWE with a
numeric
column to show that meltinginteger
together withnumeric
works fine.Created on 2018-10-01 by the reprex package (v0.2.0).
Session info
As you can see from the MWE, the former
integer64
value is now something very small and obviously wrong. Even though there is a warning, it does not warn from the actual error which was produced.NOTE: If all columns to melt are
integer64
all works fine.The text was updated successfully, but these errors were encountered: