Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 18, 2024
1 parent 1c45fa8 commit b9737b2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
4 changes: 3 additions & 1 deletion R/group_tabularray.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ group_tabularray_col <- function(x, j) {

for (k in seq_along(j)) {
z <- min(j[[k]])
args <- list(x = out,
args <- list(tt_build_now = TRUE,
x = out,
# the new header is always first row and
# style_tt always adds nhead to index
i = 1 - meta(out)$nhead,
j = z,
align = "c",
colspan = max(j[[k]]) - min(j[[k]]) + 1)
out <- do.call(style_tt, args)
}
Expand Down
3 changes: 1 addition & 2 deletions R/group_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#' @inheritParams tt
#' @inheritParams style_tt
#' @param indent integer number of `pt` to use when indenting the non-labelled rows.
#' @param ... All additional arguments (ex: `italic`, `bold`, `color`) are automatically passed to the `style_tt()` function and applied to the labels.
group_tt <- function(x, i = NULL, j = NULL, indent = 1) {

if (is.null(meta(x))) stop("`x` must be generated by `tinytable::tt()`.", call. = FALSE)
Expand All @@ -26,7 +25,7 @@ group_tt <- function(x, i = NULL, j = NULL, indent = 1) {
if (meta(out)$output == "latex") {
cal <- call("group_tabularray", i = i, j = j, indent = indent)
} else if (meta(out)$output == "html") {
cal <- call("group_botstrap", i = i, j = j, indent = indent)
cal <- call("group_bootstrap", i = i, j = j, indent = indent)
}

out <- meta(out, "lazy_group", c(meta(out)$lazy_group, list(cal)))
Expand Down
10 changes: 8 additions & 2 deletions R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#' @param bootstrap_css_rule A string with complete CSS rules that apply to the table class specified using the `theme` argument of the `tt()` function.
#' @param tabularray_inner A string that specifies the "inner" settings of a tabularray LaTeX table.
#' @param tabularray_outer A string that specifies the "outer" settings of a tabularray LaTeX table.
#' @param ... extra arguments are ignored
#' @return Returns a modified `tinytable` object with the applied styles.
#' @template latex_preamble
#' @export
Expand Down Expand Up @@ -59,7 +60,8 @@ style_tt <- function (x,
tabularray_inner = NULL,
tabularray_outer = NULL,
bootstrap_css = NULL,
bootstrap_css_rule = NULL) {
bootstrap_css_rule = NULL,
...) {

out <- x
cal <- call("style_tt_lazy",
Expand All @@ -84,7 +86,11 @@ style_tt <- function (x,
bootstrap_css = bootstrap_css,
bootstrap_css_rule = bootstrap_css_rule)

out <- meta(out, "lazy_style", c(meta(out)$lazy_style, list(cal)))
if (isTRUE(list(...)[["tt_build_now"]])) {
out <- eval(cal)
} else {
out <- meta(out, "lazy_style", c(meta(out)$lazy_style, list(cal)))
}

return(out)
}
Expand Down
12 changes: 6 additions & 6 deletions inst/tinytest/test-format_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# )
#
# Q
pkgload::load_all()
k = dat |> tt("latex") |>
style_tt(color = "orange") |>
format_tt(j = 1, digits = 10, num_fmt = "decimal") |>
format_tt(j = 2, date = "%Y")
print(k)
# pkgload::load_all()
# k = dat |> tt("latex") |>
# style_tt(color = "orange") |>
# format_tt(j = 1, digits = 10, num_fmt = "decimal") |>
# format_tt(j = 2, date = "%Y")
# print(k)
4 changes: 1 addition & 3 deletions man/group_tt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/style_tt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/tutorial.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ Here is a table with both row and column headers, as well as some styling:
```{r}
dat <- mtcars[1:9, 1:8]
tt(dat) |>
group_tt(color = "teal", italic = TRUE,
group_tt(
i = list("I like (fake) hamburgers" = 3,
"She prefers halloumi" = 4,
"They love tofu" = 7),
Expand Down

0 comments on commit b9737b2

Please sign in to comment.