Better support for big int
Opened this issue · 1 comments
mgirlich commented
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
"integer64"
: convert integer like character to int64 and integer like doubles to int64"character"
: convert numbers to character
After #153 this can be done via a simple wrapper around tib_variant()
.
mgirlich commented
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?