From 7a23c88d1c9da12097de2257f527c6b33fc660de Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Sun, 3 Nov 2024 14:47:07 -0500 Subject: [PATCH] cleanup --- R/style_tabularray.R | 130 ------------------------------------------- 1 file changed, 130 deletions(-) diff --git a/R/style_tabularray.R b/R/style_tabularray.R index 1ca4ef5c..2acee22e 100644 --- a/R/style_tabularray.R +++ b/R/style_tabularray.R @@ -232,142 +232,12 @@ setMethod( x@table_string <- tabularray_insert(x@table_string, content = s, type = "inner") } - # if (nrow(tmp) > 0) { - # tmp <- do.call(rbind, by(tmp, list(tmp$i, tmp$lin), function(k) { - # if (all(all_j %in% k$j)) { - # jval <- "" - # } else { - # jval <- paste(sort(unique(k$j)), collapse = ",") - # } - # k <- transform(k, j = jval) - # unique(k[, c("i", "j", "lin")]) - # })) - # tmp <- by(tmp, list(tmp$j, tmp$lin), function(k) { - # k$i <- paste(sort(unique(k$i)), collapse = ",") - # k <- unique(k) - # spec <- sprintf("hline{%s}={%s}{%s},", k$i, k$j, k$lin) - # }) - # for (l in tmp) { - # l <- sub("{}", "", l, fixed = TRUE) - # x@table_string <- tabularray_insert(x@table_string, l, type = "inner") - # } - # } - - # by(tmp, list(tmp$lin), function(k) { - # # - # flag <- all(all_j %in% k$j) && nrow(k) == length(all_j) * length(unique(k$i)) - # - # if () { - # k <- unique(k[, colnames(k) != "j"]) - # ival <- paste( - # spec <- sprintf( - # "hline{%s}={}{solid, %sem, %s},", - # ival, - # jval, - # width, - # sub("^#", "c", color)) - # }) - # - # if (nrow(tmp) > 0) { - # - # spec <- sprintf("top={%s}", tmp$lin[1]) - # - # - # } else { - # ival <- sprintf("{%s}", paste(unique(tmp$i), collapse = ",")) - # } - # } - # - return(x) }) - - - # lin <- sty[grepl("b|t", sty$line),, drop = FALSE] - # if (nrow(lin) > 0) { - # idx <- list(lin$i, lin$line, lin$line_color, lin$line_width) - # idx <- Filter(function(x) !all(is.na(x)), idx) - # lin <- split(lin, idx) - # lin <- Filter(function(x) nrow(x) > 0, lin) - # lin <- lapply(lin, hlines_tabularray) - # lin <- unlist(lin) - # for (l in lin) { - # x@table_string <- tabularray_insert(x@table_string, l, type = "inner") - # } - # } - # - # lin <- sty[grepl("l|r", sty$line),, drop = FALSE] - # if (nrow(lin) > 0) { - # idx <- list(lin$j, lin$line, lin$line_color, lin$line_width) - # idx <- Filter(function(x) !all(is.na(x)), idx) - # lin <- split(lin, idx) - # lin <- Filter(function(x) nrow(x) > 0, lin) - # lin <- lapply(lin, vlines_tabularray) - # lin <- unlist(lin) - # for (l in lin) { - # x@table_string <- tabularray_insert(x@table_string, l, type = "inner") - # } - # } - # - -hlines_tabularray <- function(k) { - color <- if (is.na(k$line_color[1])) "black" else k$line_color[1] - width <- if (is.na(k$line_width[1])) 0.1 else k$line_width[1] - if (grepl("b", k$line[1]) && grepl("t", k$line[1])) { - k <- rbind(k, transform(k, i = i + 1)) - } else if (grepl("b", k$line[1])) { - k <- transform(k, i = i + -1) - } - if (all(is.na(k$i))) { - ival <- "" - } else { - ival <- sprintf("{%s}", paste(unique(k$i), collapse = ",")) - } - if (all(is.na(k$j))) { - jval <- "" - } else { - jval <- sprintf("{%s}", paste(unique(k$j), collapse = ",")) - } - out <- sprintf( - "hline%s=%s{solid, %sem, %s},", - ival, - jval, - width, - sub("^#", "c", color) - ) - return(out) -} - -vlines_tabularray <- function(k) { - color <- if (is.na(k$line_color[1])) "black" else k$line_color[1] - width <- if (is.na(k$line_width[1])) 0.1 else k$line_width[1] - if (grepl("l", k$line[1]) && grepl("r", k$line[1])) { - k <- rbind(k, transform(k, j = j + 1)) - } else if (grepl("r", k$line[1])) { - k <- transform(k, j = j + 1) - } - if (all(is.na(k$i))) { - ival <- "" - } else { - ival <- sprintf("{%s}", paste(unique(k$i), collapse = ",")) - } - jval <- if (all(is.na(k$j))) "" else paste(unique(k$j), collapse = ",") - out <- sprintf( - "vline{%s}=%s{solid, %sem, %s},", - jval, - ival, - width, - sub("^#", "c", color) - ) - return(out) -} - - - tabularray_insert <- function(x, content = NULL, type = "body") { out <- x