Skip to content

Commit

Permalink
FIXES
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 11, 2023
1 parent f9e2aa4 commit f5a7a9c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
13 changes: 12 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,25 @@
# insert row
if (index == 1) {
rbind(row, data)
} else if (index == nrow(data)) {
} else if (index == (nrow(data) + 1)) {
rbind(data, row)
} else {
rbind(data[1:(index - 1), ], row, data[index:nrow(data), ])
}
}


.insert_element_at <- function(data, element, index) {
if (index == 1) {
c(element, data)
} else if (index == length(data)) {
c(data, element)
} else {
c(data[1:(index - 1)], element, data[index:length(data)])
}
}


.find_factor_levels <- function(data) {
out <- lapply(colnames(data), function(i) {
v <- data[[i]]
Expand Down
25 changes: 22 additions & 3 deletions R/utils_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,31 @@
params
}

pretty_names <- attributes(params)$pretty_names
out <- params
for (f in factors) {
min(which(f %in% out$Parameter))

for (fn in names(factors)) {
f <- factors[[fn]]
found <- which(names(pretty_names) %in% f)
if (length(found)) {
reference_level <- f[!f %in% names(pretty_names)]
pretty_level <- paste0(fn, " [", sub(fn, "", reference_level, fixed = TRUE), " (ref.)]")
pretty_names <- .insert_element_at(
pretty_names,
stats::setNames(pretty_level, reference_level),
min(found)
)
out <- .insert_row_at(
out,
data.frame(Parameter = reference_level, Coefficient = 0, stringsAsFactors = FALSE),
min(found)
)
}
attr(out, "pretty_names") <- pretty_names
attr(out, "pretty_labels") <- pretty_names
}

params
out
}


Expand Down

0 comments on commit f5a7a9c

Please sign in to comment.