melting integer64 columns together with other classes leads to wrong results

Open
#3,087 16 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
r
Domain
data

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

bit64 bug IDate/ITime reshape

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.