mgirlich / tibblify

Rectangle Nested Lists
https://mgirlich.github.io/tibblify/
GNU General Public License v3.0
67 stars 2 forks source link

Better support for big int #151

Open mgirlich opened 2 years ago

mgirlich commented 2 years ago

Big ints are often quite painful to work with. If they come from jsonlite::fromJSON() one has the issue of mixed types or loss of precision:

x <- "[
  111111111111,
  1111111111111,
  11111111111111111
]"
jsonlite::fromJSON(x, simplifyVector = FALSE, bigint_as_char = TRUE)
#> [[1]]
#> [1] 111111111111
#> 
#> [[2]]
#> [1] 1.111111e+12
#> 
#> [[3]]
#> [1] "11111111111111111"
as.character(jsonlite::fromJSON(x, simplifyVector = FALSE, bigint_as_char = FALSE))
#> [1] "111111111111"      "1111111111111"     "11111111111111112"

Created on 2022-07-26 by the reprex package (v2.0.1)

If one uses bigint_as_char = TRUE one might get mixed types. To parse them with tibblify requires tib_variant() and a conversion later on. This feels a bit awkward...

Idea: add tib_bigint(output_form = c("integer64", "character")). For

After #153 this can be done via a simple wrapper around tib_variant().

mgirlich commented 2 years ago

Maybe just add as an example in the vignette:

tib_bigint <- function(key,
                       ...,
                       required = TRUE,
                       fill = NA_character_) {
  tib_variant(
    key = key,
    required = required,
    fill = fill,
    transform = as.character
  )
}

But the formatting doesn't look nice... Add helpers for formatting?