Skip to content

Commit

Permalink
internals: remove generic add_rows
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgohel committed Jan 17, 2024
1 parent 7286fc3 commit 329fbb2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
28 changes: 4 additions & 24 deletions R/01_fpstruct.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
add_rows <- function(x, ...) {
UseMethod("add_rows")
}

# fpstruct ------

fpstruct <- function(nrow, keys, default) {
Expand Down Expand Up @@ -45,7 +41,7 @@ get_fpstruct_elements <- function(x, i, j) {


#' @importFrom utils head tail
add_rows.fpstruct <- function(x, nrows, first, default = x$default, ...) {
add_rows_fpstruct <- function(x, nrows, first, default = x$default, ...) {
if (nrow(x$data) < 1) {
new <- matrix(rep(default, x$ncol * nrows), ncol = x$ncol)
} else if (first) {
Expand Down Expand Up @@ -122,9 +118,9 @@ print.text_struct <- function(x, ...) {
cat("a text_struct with ", dims[1], " rows and ", dims[2], " columns", sep = "")
}

add_rows.text_struct <- function(x, nrows, first, ...) {
add_rows_to_struct <- function(x, nrows, first, ...) {
for (i in seq_len(length(x))) {
x[[i]] <- add_rows(x[[i]], nrows, first = first)
x[[i]] <- add_rows_fpstruct(x[[i]], nrows, first = first)
}
x
}
Expand Down Expand Up @@ -184,15 +180,6 @@ print.par_struct <- function(x, ...) {
cat("a par_struct with ", dims[1], " rows and ", dims[2], " columns", sep = "")
}


add_rows.par_struct <- function(x, nrows, first, ...) {
for (i in seq_len(length(x))) {
x[[i]] <- add_rows(x[[i]], nrows, first = first)
}
x
}


`[<-.par_struct` <- function(x, i, j, property, value) {
if (inherits(value, "fp_par")) {
value <- cast_borders(value)
Expand Down Expand Up @@ -264,13 +251,6 @@ cell_struct <- function(nrow, keys,
x
}

add_rows.cell_struct <- function(x, nrows, first, ...) {
for (i in seq_len(length(x))) {
x[[i]] <- add_rows(x[[i]], nrows, first = first)
}
x
}

`[<-.cell_struct` <- function(x, i, j, property, value) {
if (inherits(value, "fp_cell")) {
value <- cast_borders(value)
Expand Down Expand Up @@ -338,7 +318,7 @@ add_rows_to_chunkset_struct <- function(x, nrows, first, data, ...) {
names_ <- names(data)
stopifnot(!is.null(names_))

x <- add_rows.fpstruct(x, nrows, first = first, default = as_paragraph(as_chunk("")))
x <- add_rows_fpstruct(x, nrows, first = first, default = as_paragraph(as_chunk("")))
if (first) {
id <- seq_len(nrows)
} else {
Expand Down
6 changes: 3 additions & 3 deletions R/augment_rows.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ add_rows_to_tabpart <- function(x, rows, first = FALSE) {
ncol <- length(x$col_keys)
nrow <- nrow(rows)

x$styles$cells <- add_rows(x$styles$cells, nrows = nrow, first = first)
x$styles$pars <- add_rows(x$styles$pars, nrows = nrow, first = first)
x$styles$text <- add_rows(x$styles$text, nrows = nrow, first = first)
x$styles$cells <- add_rows_to_struct(x$styles$cells, nrows = nrow, first = first)
x$styles$pars <- add_rows_to_struct(x$styles$pars, nrows = nrow, first = first)
x$styles$text <- add_rows_to_struct(x$styles$text, nrows = nrow, first = first)
x$content <- add_rows_to_chunkset_struct(x$content, nrows = nrow, first = first, rows)

span_new <- matrix(1, ncol = ncol, nrow = nrow)
Expand Down

0 comments on commit 329fbb2

Please sign in to comment.