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

Improve implementation of all vec_*() functions #995

Merged
merged 57 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
9cba44b
Rewrite `context_missing_text()`
rich-iannone Jul 29, 2022
c361734
Make several corrections to testthat tests
rich-iannone Jul 29, 2022
bdf387a
Change HTML entity to Unicode code point
rich-iannone Aug 1, 2022
eeebec9
Update affected tests
rich-iannone Aug 1, 2022
be36476
Modify `context_exp_marks()` in the `html` case
rich-iannone Aug 2, 2022
bb56558
Update several testthat tests
rich-iannone Aug 2, 2022
77408a7
Rewrite the `context_plusminus_mark()` fn
rich-iannone Aug 2, 2022
06a6222
Update gt_styles_default.scss
rich-iannone Aug 2, 2022
7b8a80c
Update utils_render_common.R
rich-iannone Aug 2, 2022
687ac08
Update test-cols_merge.R
rich-iannone Aug 2, 2022
6692554
`devtools::document()` (GitHub Actions)
rich-iannone Aug 2, 2022
75b8b34
Add necessary `match.arg()` call to reduce `layout`
rich-iannone Aug 2, 2022
c93ed89
Modify order of defaults for `layout` in `fmt_fraction()`
rich-iannone Aug 2, 2022
391b2d2
Update format_vec.R
rich-iannone Aug 2, 2022
2eefcf7
Update help files using roxygen
rich-iannone Aug 2, 2022
12350e5
Merge branch 'remove-html-entities' of https://github.com/rstudio/gt …
rich-iannone Aug 2, 2022
648128a
Update vec_fmt_fraction.Rd
rich-iannone Aug 2, 2022
b7e2cb6
Add more output options, including 'auto'
rich-iannone Aug 3, 2022
051baa9
Tweak word and default exponent marks
rich-iannone Aug 3, 2022
6e207d9
Update help files using roxygen
rich-iannone Aug 3, 2022
ec32398
Update several testthat tests
rich-iannone Aug 3, 2022
8afa3bb
Make correction to `cli_abort()` stmt
rich-iannone Aug 3, 2022
3b58015
Improve messaging in `cli_abort()` stmt
rich-iannone Aug 3, 2022
74001fa
Include 'word' as an output option in `vec_*()` fns
rich-iannone Aug 3, 2022
3d089ea
Update gt_styles_default.scss
rich-iannone Aug 3, 2022
17a1ff6
Improve HTML output in the `fmt_fraction()` fn
rich-iannone Aug 3, 2022
e80969a
Update several testthat tests
rich-iannone Aug 3, 2022
2e51a41
`devtools::document()` (GitHub Actions)
rich-iannone Aug 3, 2022
088e491
Update help files using roxygen
rich-iannone Aug 3, 2022
b294095
Update _pkgdown.yml
rich-iannone Aug 3, 2022
3688490
Refactor `vec_*()` fns
rich-iannone Aug 3, 2022
9d578cf
Update vec_fmt_number.Rd
rich-iannone Aug 3, 2022
d7aca55
Make correction to `cli_abort()` stmt
rich-iannone Aug 3, 2022
9208b0c
Update format_data.R
rich-iannone Aug 3, 2022
12d5b35
Update several testthat tests
rich-iannone Aug 3, 2022
64b123e
Modify permille and permyriad marks
rich-iannone Aug 3, 2022
8974e0e
Add the `vec_fmt_partsper()` fn
rich-iannone Aug 3, 2022
cfeb62b
Update NAMESPACE
rich-iannone Aug 3, 2022
be42334
Add comments
rich-iannone Aug 3, 2022
15666e2
Create vec_fmt_partsper.Rd
rich-iannone Aug 3, 2022
783d255
Update help files using roxygen
rich-iannone Aug 3, 2022
7445487
Update _pkgdown.yml
rich-iannone Aug 3, 2022
ea73703
Update format_vec.R
rich-iannone Aug 3, 2022
fd13e8b
Add the `vec_fmt_duration()` fn
rich-iannone Aug 3, 2022
9e33335
Update NAMESPACE
rich-iannone Aug 3, 2022
f1218ab
Create vec_fmt_duration.Rd
rich-iannone Aug 3, 2022
bc91907
Update _pkgdown.yml
rich-iannone Aug 3, 2022
525822a
Update help files using roxygen
rich-iannone Aug 3, 2022
7d1c353
`devtools::document()` (GitHub Actions)
rich-iannone Aug 3, 2022
2c0965c
Update format_vec.R
rich-iannone Aug 4, 2022
faba907
Merge branch 'remove-html-entities' of https://github.com/rstudio/gt …
rich-iannone Aug 4, 2022
6f6553b
Update vec_fmt_duration.Rd
rich-iannone Aug 4, 2022
7783c79
Create vec_fmt_duration.Rd
rich-iannone Aug 4, 2022
d88e415
Update format_vec.R
rich-iannone Aug 4, 2022
616ceb3
Update vec_fmt_duration.Rd
rich-iannone Aug 4, 2022
abbc4ce
Add several testthat tests
rich-iannone Aug 4, 2022
99c962a
Add several testthat tests
rich-iannone Aug 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ export(vec_fmt_bytes)
export(vec_fmt_currency)
export(vec_fmt_date)
export(vec_fmt_datetime)
export(vec_fmt_duration)
export(vec_fmt_engineering)
export(vec_fmt_fraction)
export(vec_fmt_integer)
export(vec_fmt_markdown)
export(vec_fmt_number)
export(vec_fmt_partsper)
export(vec_fmt_percent)
export(vec_fmt_scientific)
export(vec_fmt_time)
Expand Down
81 changes: 52 additions & 29 deletions R/format_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,10 @@ fmt_partsper <- function(
#' option to simplify the fraction (where possible) can be taken with `TRUE`
#' (the default). With `FALSE`, denominators in fractions will be fixed to the
#' value provided in `accuracy`.
#' @param layout For HTML output, the `"diagonal"` layout is the default. This
#' will generate fractions that are typeset with raised/lowered numerals and a
#' virgule. The `"inline"` layout places the numerals of the fraction on the
#' baseline and uses a standard slash character.
#' @param layout For HTML output, the `"inline"` layout is the default. This
#' layout places the numerals of the fraction on the baseline and uses a
#' standard slash character. The `"diagonal"` layout will generate fractions
#' that are typeset with raised/lowered numerals and a virgule.
#'
#' @return An object of class `gt_tbl`.
#'
Expand Down Expand Up @@ -1350,7 +1350,8 @@ fmt_partsper <- function(
#' fmt_fraction(
#' columns = starts_with("f_"),
#' accuracy = 10,
#' simplify = FALSE
#' simplify = FALSE,
#' layout = "diagonal"
#' ) %>%
#' sub_missing(missing_text = "") %>%
#' tab_spanner(
Expand Down Expand Up @@ -1399,14 +1400,13 @@ fmt_fraction <- function(
rows = everything(),
accuracy = NULL,
simplify = TRUE,
layout = c("diagonal", "inline"),
layout = c("inline", "diagonal"),
use_seps = TRUE,
pattern = "{x}",
sep_mark = ",",
system = c("intl", "ind"),
locale = NULL
) {

system <- match.arg(system)

# Perform input object validation
Expand Down Expand Up @@ -1602,21 +1602,45 @@ fmt_fraction <- function(

if (context == "html") {

narrow_no_break_space_char <- "\U0202F"
slash_mark_char <- "\U02044"

num_vec <-
paste0("<span class=\"gt_fraction_numerator\">", num_vec, "</span>")
paste0(
"<span style=\"",
"font-size:0.6em;",
"line-height:0.6em;",
"vertical-align:0.45em;",
"\">",
num_vec,
"</span>"
)

denom_vec <-
paste0("<span class=\"gt_fraction_denominator\">", denom_vec, "</span>")
paste0(
"<span style=\"",
"font-size:0.6em;",
"line-height:0.6em;",
"vertical-align:-0.05em;",
"\">",
denom_vec,
"</span>"
)

slash_mark <-
htmltools::tags$span(
class = "gt_slash_mark",
htmltools::HTML("&frasl;")
paste0(
"<span style=\"",
"font-size:0.7em;",
"line-height:0.7em;",
"vertical-align:0.15em;",
"\">",
slash_mark_char,
"</span>"
)

x_str[has_a_fraction] <-
paste0(
gsub(" ", "&#8239;", non_fraction_part),
gsub(" ", narrow_no_break_space_char, non_fraction_part),
num_vec, slash_mark, denom_vec
)

Expand Down Expand Up @@ -2842,7 +2866,7 @@ fmt_duration <- function(
cli::cli_abort(c(
"The value provided for `trim_zero_units` is invalid. Either use:",
"*" = "`TRUE` or `FALSE`, or",
"*" = "A vector with any of the keywords `\"leading\"`, `\"trailing\"`, or `\"internal\"`."
"*" = "A vector with any of the keywords \"leading\", \"trailing\", or \"internal\"."
))
}

Expand Down Expand Up @@ -2871,7 +2895,7 @@ fmt_duration <- function(
)
) {
cli::cli_abort(c(
"The `fmt_duration()` function can only be used on `columns` of certain types:",
"The `fmt_duration()` function can only be used on `columns` of certain types.",
"*" = "Allowed types are `numeric` and `difftime`."
))
}
Expand All @@ -2885,11 +2909,10 @@ fmt_duration <- function(
) &&
is.null(input_units)
) {
stop(
"When there are numeric columns to format, `input_units` must not be `NULL`:\n",
"* Use one of `\"seconds\"`, `\"minutes\"`, `\"hours\"`, `\"days\"`, or `\"weeks\"`",
call. = FALSE
)
cli::cli_abort(c(
"When there are numeric columns to format, `input_units` must not be `NULL`.",
"*" = "Use one of \"seconds\", \"minutes\", \"hours\", \"days\", or \"weeks\"."
))
}

# Initialize `colon_sep_params` list
Expand Down Expand Up @@ -3027,12 +3050,12 @@ fmt_duration <- function(
validate_trim_zero_units <- function(trim_zero_units) {

if (!all(trim_zero_units %in% c("leading", "trailing", "internal"))) {
stop(
"The character vector provided for `trim_zero_units` is invalid:\n",
"* It should only contain any of the keywords `\"leading\"`, `\"trailing\"`,
or ", "`\"internal\"`",
call. = FALSE
)

cli::cli_abort(c(
"The character vector provided for `trim_zero_units` is invalid.",
"*" = "It should only contain any of the keywords \"leading\", \"trailing\",
or ", "\"internal\"."
))
}
}

Expand All @@ -3054,7 +3077,7 @@ validate_duration_input_units <- function(input_units) {
if (!all(input_units %in% time_parts_vec) || length(input_units) != 1) {

cli::cli_abort(c(
"The value of `input_units` for `fmt_duration()` is invalid:",
"The value of `input_units` for `fmt_duration()` is invalid.",
"*" = "Only one of the \"weeks\", \"days\", \"hours\", \"minutes\", or
\"seconds\" time parts should be present."
))
Expand Down Expand Up @@ -3091,9 +3114,9 @@ validate_duration_output_units <- function(output_units) {
if (!all(output_units %in% time_parts_vec)) {

cli::cli_abort(c(
"There are invalid components in the `output_units` input to `fmt_duration()`:",
"There are invalid components in the `output_units` input to `fmt_duration()`.",
"*" = "Only the \"weeks\", \"days\", \"hours\", \"minutes\", and \"seconds\`
time parts should be present"
time parts should be present."
))
}
}
Expand Down
Loading