Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for big int #151

Open
mgirlich opened this issue Jul 26, 2022 · 1 comment
Open

Better support for big int #151

mgirlich opened this issue Jul 26, 2022 · 1 comment

Comments

@mgirlich
Copy link
Owner

mgirlich commented Jul 26, 2022

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 mgirlich added this to the 0.2.1 milestone Jul 26, 2022
@mgirlich
Copy link
Owner Author

mgirlich commented Nov 9, 2022

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?

@mgirlich mgirlich removed this from the 0.2.1 milestone Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant