Skip to content

Commit

Permalink
tabularray break up is successful
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 16, 2024
1 parent 5361c67 commit 6da64ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
6 changes: 4 additions & 2 deletions R/style_tabularray.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ style_tabularray <- function(x,
b <- sprintf(
"\\tinytableDefineColor{%s}{HTML}{%s}",
sub("^#", "c", h), sub("^#", "", h))
cal <- call("insert_tabularray", content = b, type = "body")
cal <- call("tabularray_insert", content = b, type = "body")
out <- meta(out, "lazy_style", c(meta(out)$lazy_style, list(cal)))
}
}
Expand Down Expand Up @@ -129,7 +129,9 @@ tabularray_insert <- function(x, content = NULL, type = "body") {
idx <- grep(comment, out)

content <- trimws(content)
if (!grepl(",$", content)) content <- paste0(content, ",")
if (!grepl(",$", content) && type != "body") {
content <- paste0(content, ",")
}

if (type == "body") {
out <- c(out[1:idx], content, out[(idx + 1):length(out)])
Expand Down
20 changes: 7 additions & 13 deletions R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,15 @@ style_tt <- function (x,
if (!isTRUE(meta(x)$output %in% c("html", "latex"))) return(x)

out <- x
if (is.null(i)) {
ival <- seq_len(meta(x)$nrows)
} else {
ival <- i
}
if (is.null(j)) {
jval <- seq_len(meta(x)$ncols)
} else {
if (is.character(j) && length(j) == 1 && is.character(meta(x)$colnames)) {
jval <- grep(j, meta(x)$colnames, perl = TRUE)
} else {
jval <- j
}

# j is a regular expression
if (is.character(j) && !is.null(meta(x, "colnames"))) {
j <- grep(j, meta(x, "colnames"), perl = TRUE)
}

if (is.null(i)) ival <- seq_len(meta(x)$nrows) else ival <- i
if (is.null(j)) jval <- seq_len(meta(x)$nrows) else jval <- j

assert_style_tt(
x = x, i = i, j = j, ival = ival, jval = jval, bold = bold, italic = italic, monospace = monospace, underline = underline, strikeout = strikeout,
color = color, background = background, fontsize = fontsize, width = width, align = align, colspan = colspan, indent = indent,
Expand Down
2 changes: 1 addition & 1 deletion vignettes/tutorial.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ With the `save_tt()` function, users can also save tables directly to PNG images
# PNG
tt(x, output = "html") |> save_tt("path/to/file.png")

# PDF
# HTML
tt(x, output = "html") |> save_tt("path/to/file.html")

# PDF
Expand Down

0 comments on commit 6da64ab

Please sign in to comment.