Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Nov 3, 2024
1 parent 3a343bb commit 7a23c88
Showing 1 changed file with 0 additions and 130 deletions.
130 changes: 0 additions & 130 deletions R/style_tabularray.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7a23c88

Please sign in to comment.