Skip to content

Commit

Permalink
Merge branch 'main' into revdep_0_4_0
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Aug 23, 2024
2 parents 0854b10 + 4f7ca13 commit 35584eb
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ MathJax = {
* `glue::glue()` string is accepted by `format_tt()`. Thanks to @LukasWallrich for report #792 on the `modelsummary` repository.
* Support Github Flavored Markdown (`gfm`) output. Thanks to @kylebutts for contribution #315.
* `theme_tt("rotate")` to rotate tables in LaTeX or Typst.
* `save_tt("/path/to/file")` returns the file path invisibly. Thanks to @yjunechoe for issue #328.

### HTML

Expand Down
2 changes: 1 addition & 1 deletion R/group_bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ group_bootstrap_col <- function(x, j, ihead, ...) {
# midrule on numbered spans (not full columns of body)
jnames <- names(j)
jnames <- seq_along(jnames)[trimws(jnames) != ""]
x <- style_eval(x, i = ihead, j = jnames, line = "b", line_width = .05, line_color = "#d3d8dc")
x <- style_eval(x, i = ihead, j = jnames, line = "b", line_width = 0.05, line_color = "#d3d8dc")

return(x)
}
Expand Down
4 changes: 2 additions & 2 deletions R/group_tabularray.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ insert_values <- function(vec, values, positions) {
positions <- positions[ord]

# Create a vector of indices for the original vector
original_indices <- 1:length(vec)
original_indices <- seq_along(vec)


# Insert values and update indices
for (i in 1:length(values)) {
for (i in seq_along(values)) {
vec <- append(vec, values[i], after = positions[i] - 1)
original_indices <- append(original_indices, NA, after = positions[i] - 1)
}
Expand Down
2 changes: 1 addition & 1 deletion R/group_typst.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ group_typst_col <- function(x, j, ihead, ...) {
idx <- order(max_col)
j <- j[idx]
lab <- names(j)
len <- sapply(j, length)
len <- lengths(j)
col <- ifelse(
trimws(lab) == "",
sprintf("[%s],", lab),
Expand Down
4 changes: 2 additions & 2 deletions R/save_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' + If `output` is "markdown", "latex", "html", or "typst", the table is returned in a string as an `R` object.
#' + If `output` is a valid file path, the table is saved to file. The supported extensions are: .docx, .html, .png, .pdf, .tex, .typ, and .md (with aliases .txt, .Rmd and .qmd).
#' @param overwrite A logical value indicating whether to overwrite an existing file.
#' @return A string or `TRUE` when the table is written to file.
#' @return A string with the table when `output` is a format, and the file path when `output` is a valid path.
#' @export
#' @examples
#' library(tinytable)
Expand Down Expand Up @@ -126,7 +126,7 @@ save_tt <- function(x, output, overwrite = FALSE) {
pandoc::pandoc_convert(text = x@table_string, to = "docx", output = output)
}

return(invisible(TRUE))
return(invisible(path.expand(output)))
}


Expand Down
2 changes: 1 addition & 1 deletion R/style_bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ setMethod(
alignv = NULL,
line = NULL,
line_color = "black",
line_width = .1,
line_width = 0.1,
colspan = NULL,
rowspan = NULL,
indent = 0,
Expand Down
2 changes: 1 addition & 1 deletion R/style_tabularray.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ setMethod(
alignv = NULL,
line = NULL,
line_color = "black",
line_width = .1,
line_width = 0.1,
colspan = NULL,
rowspan = NULL,
indent = 0,
Expand Down
2 changes: 1 addition & 1 deletion R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ style_tt_lazy <- function (x,
msg <- sprintf("`align` must be a single character or a string of length %s.", nalign)
stop(msg, call. = FALSE)
}
if (any(!align %in% c("c", "l", "r", "d"))) {
if (!all(align %in% c("c", "l", "r", "d"))) {
msg <- "`align` must be characters c, l, r, or d."
stop(msg, call. = FALSE)
}
Expand Down
4 changes: 2 additions & 2 deletions R/style_typst.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ setMethod(
align = NULL,
line = NULL,
line_color = "black",
line_width = .1,
line_width = 0.1,
colspan = NULL,
indent = 0,
midrule = FALSE, # undocumented, only used by `group_tt()`
Expand Down Expand Up @@ -132,7 +132,7 @@ setMethod(
out <- lines_drop(out, "// tinytable align-default-array here", fixed = TRUE)
out <- lines_insert(out, align_default, "tinytable align-default-array after", "after")
} else if (length(align_value) %in% c(1, length(ival) * length(jval))) {
if (length(align_value == 1)) align_value <- rep(align_value, length(ival) * length(jval))
if (length(align_value) == 1) align_value <- rep(align_value, length(ival) * length(jval))
counter <- 0
for (k in ival) {
for (w in jval) {
Expand Down
18 changes: 9 additions & 9 deletions R/theme_tt.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
theme_default <- function(x, ...) {
fn <- function(table) {
if (isTRUE(table@output == "typst")) {
table <- style_eval(table, i = 1 - table@nhead, line = "t", line_width = .1)
table <- style_eval(table, i = 0, line = "b", line_width = .05)
table <- style_eval(table, i = nrow(table), line = "b", line_width = .1)
table <- style_eval(table, i = 1 - table@nhead, line = "t", line_width = 0.1)
table <- style_eval(table, i = 0, line = "b", line_width = 0.05)
table <- style_eval(table, i = nrow(table), line = "b", line_width = 0.1)
}

return(table)
Expand Down Expand Up @@ -168,12 +168,12 @@ theme_striped <- function(x, ...) {
assert_class(x, "tinytable")
fn <- function(table) {
if (isTRUE(table@output == "typst")) {
table <- style_eval(table, i = 1 - table@nhead, line = "t", line_width = .1)
table <- style_eval(table, i = 0, line = "b", line_width = .05)
table <- style_eval(table, i = nrow(table), line = "b", line_width = .1)
table <- style_eval(table, i = 1 - table@nhead, line = "t", line_width = .1)
table <- style_eval(table, i = 0, line = "b", line_width = .05)
table <- style_eval(table, i = nrow(table), line = "b", line_width = .1)
table <- style_eval(table, i = 1 - table@nhead, line = "t", line_width = 0.1)
table <- style_eval(table, i = 0, line = "b", line_width = 0.05)
table <- style_eval(table, i = nrow(table), line = "b", line_width = 0.1)
table <- style_eval(table, i = 1 - table@nhead, line = "t", line_width = 0.1)
table <- style_eval(table, i = 0, line = "b", line_width = 0.05)
table <- style_eval(table, i = nrow(table), line = "b", line_width = 0.1)
table <- style_eval(table, i = seq(1, nrow(table), by = 2), background = "#ededed")
}
return(table)
Expand Down
2 changes: 1 addition & 1 deletion R/tt_bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ setMethod(

if (is.null(x@theme[[1]]) || is.function(x@theme[[1]]) || isTRUE("default" %in% x@theme[[1]])) {
x <- style_eval(x, bootstrap_class = "table table-borderless",
i = 0, line = "b", line_color = "#d3d8dc", line_width = .1)
i = 0, line = "b", line_color = "#d3d8dc", line_width = 0.1)
} else if ("bootstrap" %in% x@theme[[1]]) {
x <- style_eval(x, bootstrap_class = "table")
} else if ("striped" %in% x@theme[[1]]) {
Expand Down
4 changes: 2 additions & 2 deletions R/tt_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tt_eval_grid <- function(x, width_cols = NULL, ...) {
tab <- matrix(padded, ncol = ncol(tab))

if (is.null(width_cols) || length(width_cols) == 0) {
for (j in 1:ncol(tab)) {
for (j in seq_len(ncol(tab))) {
if (isTRUE(check_dependency("fansi"))) {
width_cols[j] <- max(nchar(as.character(fansi::strip_ctl(tab[, j]))))
} else {
Expand All @@ -56,7 +56,7 @@ tt_eval_grid <- function(x, width_cols = NULL, ...) {
}
}

for (j in 1:ncol(x)) {
for (j in seq_len(ncol(x))) {
if (isTRUE(check_dependency("fansi"))) {
nc <- nchar(fansi::strip_ctl(tab[, j]))
} else {
Expand Down
2 changes: 1 addition & 1 deletion man/save_tt.Rd

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

0 comments on commit 35584eb

Please sign in to comment.