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

Overflow error with locale #11

Open
olivroy opened this issue Jul 4, 2024 · 3 comments
Open

Overflow error with locale #11

olivroy opened this issue Jul 4, 2024 · 3 comments
Assignees

Comments

@olivroy
Copy link
Collaborator

olivroy commented Jul 4, 2024

I did a bit more digging to find out that rstudio/gt#1481 is actually a bigD issue. Maybe related to https://bugs.r-project.org/show_bug.cgi?id=18618

Here is a reprex

library(bigD)
withr::with_locale(
  c("LC_TIME" = "en_CA"),
  fdt(
    input = "2021-01-09 16:32(America/Toronto)",
    format = flex_t12_lst$hms
  )
)
#> [1] "4:32:00 PM"
withr::with_locale(
  c("LC_TIME" = "fr_CA"),
  fdt(
    input = "2021-01-09 16:32(America/Toronto)",
    format = flex_t12_lst$hms
  )
)
#> Error in format.POSIXlt(as.POSIXlt(x, tz), format, usetz, ...): output string exceeded 2048 bytes
# respects locale supplied, so maybe as a workaround,
# gt could set it?
withr::with_locale(
  c("LC_TIME" = "en_CA"),
  fdt(
    input = "2021-01-09 16:32(America/Toronto)",
    format = flex_t12_lst$hms,
    locale = "fr_CA"
  )
)
#> [1] "4 h 32 min 00 s p.m."

Created on 2024-07-04 with reprex v2.1.0

Possibly gt should set the option before attempting to do it.

test case can be

# compare output of this test vs the other one.
test_that("fdt() works with non-standard locale when LC_TIME = 'en_CA' (#11).", {
  withr::local_locale("LC_TIME" = "en_CA")
  expect_no_error(
    res0 <- fdt(
      input = "2021-01-09 16:32(America/Toronto)",
      format = flex_t12_lst$hms,
      locale = "en"
    )
  )
  expect_no_error(
    res1 <- fdt(
      input = "2021-01-09 16:32(America/Toronto)",
      format = flex_t12_lst$hms,
      locale = "en"
    )
  )
})

test_that("fdt() works with non-standard locale when LC_TIME = 'fr_CA' (#11).", {
  withr::local_locale("LC_TIME" = "fr_CA")

  expect_no_error(
    res0 <- fdt(
      input = "2021-01-09 16:32(America/Toronto)",
      format = flex_t12_lst$hms,
    )
  )
  expect_no_error(
    res1 <- fdt(
      input = "2021-01-09 16:32(America/Toronto)",
      format = flex_t12_lst$hms,
      locale = "en"
    )
  )
})
@rich-iannone
Copy link
Member

@olivroy I just re-cloned the package, built from main, ran the code examples and didn't experience any errors. Perhaps this issue was fixed since the CRAN release (could be there is now a default locale set by bigD). Could you install the dev version and try again?

@olivroy
Copy link
Collaborator Author

olivroy commented Jul 5, 2024

I tried the dev version. This seems to be a Windows only problem?

@olivroy
Copy link
Collaborator Author

olivroy commented Jul 10, 2024

Ended up just putting this in my .Renviron, and it solves my issue! No need to bother if no one else complains

LC_TIME = "en-CA"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants