Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions R/utils_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@

.add_obs_row <- function(x, att, style) {
observations <- unlist(lapply(att, function(i) {
if (is.null(i$n_obs)) {

Check warning on line 229 in R/utils_format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/utils_format.R,line=229,col=5,[coalesce_linter] Use x %||% y instead of if (is.null(x)) y else x.
NA
} else {
i$n_obs
}
}))
weighted_observations <- unlist(lapply(att, function(i) {
if (is.null(i$weighted_nobs)) {

Check warning on line 236 in R/utils_format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/utils_format.R,line=236,col=5,[coalesce_linter] Use x %||% y instead of if (is.null(x)) y else x.
NA
} else {
i$weighted_nobs
Expand Down Expand Up @@ -428,13 +428,19 @@
# iterate all factors in the data and check if any factor was used in the model
for (fn in names(factors)) {
f <- factors[[fn]]
# for models from pscl, we have "count_" and "zero_" prefixes, which
# we need to add to "f" names, so that we can match them with the parameters
if (inherits(model, c("zeroinfl", "hurdle"))) {
f <- c(paste0("count_", f), paste0("zero_", f))
}
Comment on lines +258 to +262
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It would be beneficial to add a comment explaining why these prefixes are necessary for pscl models. This enhances code understanding and maintainability.

    # for models from pscl, we have "count_" and "zero_" prefixes,
    # which we need to add to "f" names, so that we can match them with the parameters
    # (pscl models require these prefixes for parameter identification)
    if (inherits(model, c("zeroinfl", "hurdle"))) {

# "f" contains all combinations of factor name and levels from the data,
# which we can match with the names of the pretty_names vector
found <- which(names(pretty_names) %in% f)
# if we have a match, we add the reference level to the pretty_names vector
if (length(found)) {
# the reference level is *not* in the pretty names yet
reference_level <- f[!f %in% names(pretty_names)]
reference_level <- gsub("^(count_|zero_)", "", reference_level, fixed = TRUE)
Comment on lines 269 to +270
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a comment explaining why this gsub call is necessary. What potential issues does it resolve?

      # Remove the count_ or zero_ prefix from the reference level
      reference_level <- gsub("^(count_|zero_)", "", reference_level, fixed = TRUE)


# for on-the-fly conversion of factors, the names of the factors can
# can also contain "factor()" or "as.factor()" - we need to remove these
Expand All @@ -452,11 +458,11 @@
if (all(grepl(pattern_cut_right, pretty_level))) {
lower_bounds <- gsub(pattern_cut_right, "\\2", pretty_level)
upper_bounds <- gsub(pattern_cut_right, "\\3", pretty_level)
pretty_level <- gsub(pattern_cut_right, paste0("\\1>", as.numeric(lower_bounds), "-", upper_bounds, "]"), pretty_level)

Check warning on line 461 in R/utils_format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/utils_format.R,line=461,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.
} else if (all(grepl(pattern_cut_left, pretty_level))) {
lower_bounds <- gsub(pattern_cut_left, "\\2", pretty_level)
upper_bounds <- gsub(pattern_cut_left, "\\3", pretty_level)
pretty_level <- gsub(pattern_cut_left, paste0("\\1", as.numeric(lower_bounds), "-<", upper_bounds, "]"), pretty_level)

Check warning on line 465 in R/utils_format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/utils_format.R,line=465,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 126 characters.
}
# insert new pretty level at the correct position in "pretty_names"
pretty_names <- .insert_element_at(
Expand Down Expand Up @@ -580,7 +586,7 @@

# helper to format the header / subheader of different model components --------------

.format_model_component_header <- function(x,

Check warning on line 589 in R/utils_format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/utils_format.R,line=589,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 51 to at most 40.
type,
split_column,
is_zero_inflated,
Expand Down Expand Up @@ -966,7 +972,7 @@
# or edge cases...

#' @keywords internal
.format_columns_multiple_components <- function(x,

Check warning on line 975 in R/utils_format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/utils_format.R,line=975,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 97 to at most 40.
pretty_names,
split_column = "Component",
digits = 2,
Expand Down
Loading