Bit 64 integers with fst

I have data in csv containing long integers. I exchange this data between csvs and fstfiles.

For instance,

library(bit64)
library(data.table)
library(fst)
library(magrittr)

# Prepare example csvs
DT64_orig <- data.table(x = (c(2345612345679, 1234567890, 8714567890)))
fwrite(DT64_orig, "DT64_orig.csv")

# Read and move to fst
DT64 <- fread("DT64_orig.csv")
write.fst(DT64, "DT64_fst.fst")

DT_fst2 <- 
  read.fst("DT64_fst.fst") %>%
  setDT

# bit64 integers not preserved:
identical(DT_fst2, DT64)

Is there a way to use fstfiles for data.tablecontaining bit64integers

+4
source share
2 answers

It looks like it fstcan discard the attributes of the column either when saving or when loading (ask the question in the package fst). You can put the column types back in the meantime. bit64::integer64is simple doubleunder the hood, so no bits are lost. Just enter type R information to print the column.

> DT_fst2
               x
1: 1.158886e-311
2: 6.099576e-315
3: 4.305569e-314
> setattr(DT_fst2$x, "class", "integer64")
> DT_fst2
               x
1: 2345612345679
2:    1234567890
3:    8714567890
> identical(DT_fst2, DT64)
[1] TRUE
+5
source

, fst . , , , . , Date POSIXt. , fst , (, ).

+3

Source: https://habr.com/ru/post/1670478/


All Articles