melting integer64 columns together with other classes leads to wrong results
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
Research direction
Start by running the provided R MWE with data.table and bit64, then inspect the melt.data.table() entry point and its handling of integer, numeric, and integer64 measure variables. Done means the melted col_int64 value remains 2147483648 rather than becoming a tiny incorrect value, with behavior covered by a regression test.
Written by the indexing model from the issue text.
Description
I think I found a bug in melt.data.table(). I want to melt several columns of class integer and integer64. When I melt these columns into a single one, the values from the former integer64 columns show weird values.
I extended the MWE with a numeric column to show that melting integer together with numeric works fine.
suppressPackageStartupMessages(library(data.table))
#> Warning: package 'data.table' was built under R version 3.5.1
suppressPackageStartupMessages(library(bit64))
DT <- data.table(key.var = "A", col_int = 2147483647L, col_num = 2147483647, col_int64 = 2147483648)
DT[, col_int64 := as.integer64(col_int64)]
print(DT)
#> key.var col_int col_num col_int64
#> 1: A 2147483647 2147483647 2147483648
sapply(DT, class)
#> key.var col_int col_num col_int64
#> "character" "integer" "numeric" "integer64"
melt.data.table(DT, id.vars = "key.var")
#> Warning in melt.data.table(DT, id.vars = "key.var"):
#> 'measure.vars' [col_int, col_num, col_int64] are not all of the same
#> type. By order of hierarchy, the molten data value column will be of type
#> 'double'. All measure variables not of type 'double' will be coerced too.
#> Check DETAILS in ?melt.data.table for more on coercion.
#> key.var variable value
#> 1: A col_int 2.147484e+09
#> 2: A col_num 2.147484e+09
#> 3: A col_int64 1.060998e-314
Created on 2018-10-01 by the reprex package (v0.2.0).
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.5.0 (2018-04-23)
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate German_Germany.1252
#> tz Europe/Berlin
#> date 2018-10-01
#> Packages -----------------------------------------------------------------
#> package * version date source
#> backports 1.1.2 2017-12-13 CRAN (R 3.5.0)
#> base * 3.5.0 2018-04-23 local
#> bit * 1.1-14 2018-05-29 CRAN (R 3.5.0)
#> bit64 * 0.9-7 2017-05-08 CRAN (R 3.5.0)
#> compiler 3.5.0 2018-04-23 local
#> data.table * 1.11.4 2018-05-27 CRAN (R 3.5.1)
#> datasets * 3.5.0 2018-04-23 local
#> devtools 1.13.6 2018-06-27 CRAN (R 3.5.1)
#> digest 0.6.15 2018-01-28 CRAN (R 3.5.1)
#> evaluate 0.11 2018-07-17 CRAN (R 3.5.1)
#> graphics * 3.5.0 2018-04-23 local
#> grDevices * 3.5.0 2018-04-23 local
#> htmltools 0.3.6 2017-04-28 CRAN (R 3.5.1)
#> knitr 1.20 2018-02-20 CRAN (R 3.5.1)
#> magrittr 1.5 2014-11-22 CRAN (R 3.5.1)
#> memoise 1.1.0 2017-04-21 CRAN (R 3.5.1)
#> methods * 3.5.0 2018-04-23 local
#> Rcpp 0.12.18 2018-07-23 CRAN (R 3.5.1)
#> rmarkdown 1.10 2018-06-11 CRAN (R 3.5.1)
#> rprojroot 1.3-2 2018-01-03 CRAN (R 3.5.1)
#> stats * 3.5.0 2018-04-23 local
#> stringi 1.1.7 2018-03-12 CRAN (R 3.5.0)
#> stringr 1.3.1 2018-05-10 CRAN (R 3.5.1)
#> tools 3.5.0 2018-04-23 local
#> utils * 3.5.0 2018-04-23 local
#> withr 2.1.2 2018-03-15 CRAN (R 3.5.1)
#> yaml 2.2.0 2018-07-25 CRAN (R 3.5.1)
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.
- Dominant language
- R
- Stars
- 3.9k
- Forks
- 1.1k
- Avg merge
- 14h 4m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Rdatatable/data.table
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one) Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Rdatatable/data.table#7887 ·
-
consistency tests
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#7853 · 3 comments ·
-
internals
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#6938 · 1 comment ·
-
encoding fread
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#5179 · 8 comments ·
-
documentation programming
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#3199 · 3 comments ·
All issues in Rdatatable/data.table
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enviPathR OpenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Bioconductor/BiocContributions#207 · 6 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
datacarpentry/semester-biology#1255 ·