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
format_tt mishandles Inf, NaN, and NA #218
Comments
Thanks a lot for the report. I can confirm that I see the same error in the To clarify, do you agree that the default behavior of
Keep in mind that the default argument is library(tinytable)
data.frame(x = 1, y = Inf) |> tt() |> format_tt()
data.frame(x = 1, y = NaN) |> tt() |> format_tt()
data.frame(x = 1, y = NA) |> tt() |> format_tt()
|
I had not noticed Did you change the behavior on
|
Thanks for the link. Interesting discussion. Yes, I had modified the default display of Here's a new proposal:
Examples below. You can try it by installing the branch in this PR: #220 What do you think? library(tinytable)
x <- data.frame(x = 1:5, y = c(pi, NA, NaN, -Inf, Inf))
dict <- list("-" = c(NA, NaN), "-∞" = -Inf, "∞" = Inf)
tt(x) |> format_tt(replace = "-")
+---+----------+
| x | y |
+===+==========+
| 1 | 3.141593 |
+---+----------+
| 2 | - |
+---+----------+
| 3 | NaN |
+---+----------+
| 4 | -Inf |
+---+----------+
| 5 | Inf |
+---+----------+
tt(x) |> format_tt(replace = dict)
+---+----------+
| x | y |
+===+==========+
| 1 | 3.141593 |
+---+----------+
| 2 | - |
+---+----------+
| 3 | - |
+---+----------+
| 4 | -∞ |
+---+----------+
| 5 | ∞ |
+---+----------+ |
I tested running the PR
|
Thanks for trying it out! I have added global options for all arguments in The
This means you get: library(tinytable)
x <- data.frame(x = pi, y = NA)
options(tinytable_tt_digits = 2)
tt(x)
| x | y |
|-----|-----|
| 3.1 | |
options(tinytable_format_replace = "zzz")
tt(x)
| x | y |
|-----|-----|
| 3.1 | zzz |
options(tinytable_format_replace = FALSE)
tt(x)
| x | y |
|-----|-----|
| 3.1 | NA | |
I'm fine with this approach. I think the docs are clear. Thanks for making the changes so quickly! |
With plain
tt()
all as expectedwith
format_tt()
not as expectedSetting some tinytable options cause the same problem with
tt()
The text was updated successfully, but these errors were encountered: