Skip to content

Commit c2e3fc3

Browse files
committed
fix
1 parent bf26f2c commit c2e3fc3

File tree

2 files changed

+4
-110
lines changed

2 files changed

+4
-110
lines changed

R/format.R

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,6 @@ format.parameters_model <- function(x,
116116
x <- .format_ranef_parameters(x)
117117
}
118118

119-
# group parameters - this function find those parameters that should be
120-
# grouped, reorders parameters into groups and indents lines that belong
121-
# to one group, adding a header for each group
122-
if (!is.null(groups)) {
123-
x <- .parameter_groups(x, groups)
124-
}
125-
indent_rows <- attributes(x)$indent_rows
126-
127119
# prepare output, to have in shape for printing. this function removes
128120
# empty columns, or selects only those columns that should be printed
129121
x <- .prepare_x_for_print(x, select, coef_name, s_value)
@@ -210,7 +202,7 @@ format.parameters_model <- function(x,
210202
}
211203

212204
# information about indention / row groups
213-
attr(formatted_table, "indent_rows") <- indent_rows
205+
attr(formatted_table, "indent_rows") <- groups
214206

215207
# vertical layout possible, if these have just one row
216208
if (identical(list(...)$layout, "vertical")) {
@@ -394,13 +386,6 @@ format.compare_parameters <- function(x,
394386
out <- datawizard::data_arrange(out, c("Effects", "Component"))
395387
}
396388

397-
# group parameters - this function find those parameters that should be
398-
# grouped, reorders parameters into groups and indents lines that belong
399-
# to one group, adding a header for each group
400-
if (!is.null(groups) && !identical(engine, "tt")) {
401-
out <- .parameter_groups(out, groups)
402-
}
403-
404389
# check whether to split table by certain factors/columns (like component, response...)
405390
split_by <- split_column <- .prepare_splitby_for_print(x)
406391

@@ -462,6 +447,9 @@ format.compare_parameters <- function(x,
462447
formatted_table <- .add_obs_row(formatted_table, parameters_attributes, style = select)
463448
}
464449

450+
# information about indention / row groups
451+
attr(formatted_table, "indent_rows") <- groups
452+
465453
formatted_table
466454
}
467455

R/utils_format.R

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -767,100 +767,6 @@
767767
}
768768

769769

770-
# helper grouping parameters -------------------
771-
772-
773-
.parameter_groups <- function(x, groups) {
774-
# only apply to conditional component for now
775-
if ("Component" %in% colnames(x) && !any(x$Component == "conditional")) {
776-
return(x)
777-
}
778-
if ("Component" %in% colnames(x)) {
779-
row_index <- which(x$Component == "conditional")
780-
} else {
781-
row_index <- seq_len(nrow(x))
782-
}
783-
784-
x_other <- x[-row_index, ]
785-
x <- x[row_index, ]
786-
787-
att <- attributes(x)
788-
indent_rows <- NULL
789-
indent_parameters <- NULL
790-
791-
if (is.list(groups)) {
792-
# find parameter names and replace by rowindex
793-
group_rows <- lapply(groups, function(i) {
794-
if (is.character(i)) {
795-
i <- match(i, x$Parameter)
796-
}
797-
i
798-
})
799-
800-
# validation check - check if all parameter names in the
801-
# group list are spelled correctly
802-
misspelled <- vapply(group_rows, anyNA, TRUE)
803-
804-
if (any(misspelled)) {
805-
# remove invalid groups
806-
group_rows[misspelled] <- NULL
807-
# tell user
808-
insight::format_alert(
809-
"Couldn't find one or more parameters specified in following groups:",
810-
toString(names(misspelled[misspelled])),
811-
"Maybe you misspelled parameter names?"
812-
)
813-
}
814-
815-
816-
# sort parameters according to grouping
817-
selected_rows <- unlist(group_rows)
818-
indent_parameters <- x$Parameter[selected_rows]
819-
x <- rbind(x[selected_rows, ], x[-selected_rows, ])
820-
821-
# set back correct indices
822-
groups <- 1
823-
for (i in 2:length(group_rows)) {
824-
groups <- c(groups, groups[i - 1] + length(group_rows[[i - 1]]))
825-
}
826-
names(groups) <- names(group_rows)
827-
} else {
828-
# find parameter names and replace by rowindex
829-
group_names <- names(groups)
830-
groups <- match(groups, x$Parameter)
831-
names(groups) <- group_names
832-
833-
# order groups
834-
groups <- sort(groups, na.last = TRUE)
835-
}
836-
837-
838-
empty_row <- x[1, ]
839-
for (i in seq_len(ncol(empty_row))) {
840-
empty_row[[i]] <- NA
841-
}
842-
843-
for (i in rev(seq_along(groups))) {
844-
x[seq(groups[i] + 1, nrow(x) + 1), ] <- x[seq(groups[i], nrow(x)), ]
845-
x[groups[i], ] <- empty_row
846-
}
847-
848-
# find row indices of indented parameters
849-
if (!is.null(indent_parameters)) {
850-
indent_rows <- match(indent_parameters, x$Parameter)
851-
}
852-
853-
# add other rows back
854-
if (nrow(x_other) > 0) {
855-
x <- rbind(x, x_other)
856-
}
857-
858-
attributes(x) <- utils::modifyList(att, attributes(x))
859-
attr(x, "indent_rows") <- indent_rows
860-
x
861-
}
862-
863-
864770
# .insert_row <- function(x, newrow, r) {
865771
# existingDF[seq(r+1,nrow(existingDF)+1),] <- existingDF[seq(r,nrow(existingDF)),]
866772
# existingDF[r,] <- newrow

0 commit comments

Comments
 (0)