Skip to content

Add format() method to parameters_efa objects - #1236

Merged
strengejacke merged 5 commits into
mainfrom
strengejacke/issue1234
Jun 28, 2026
Merged

Add format() method to parameters_efa objects#1236
strengejacke merged 5 commits into
mainfrom
strengejacke/issue1234

Conversation

@strengejacke

Copy link
Copy Markdown
Member

Fixes #1234

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces format() methods for PCA, EFA, and Omega parameter objects, refactoring the printing logic to delegate formatting tasks. Feedback on the changes highlights two critical issues: first, the sort argument and its sorting logic were omitted from the new format.parameters_pca method, which would cause sorting requests to be silently ignored; second, calling format() with positional arguments is highly error-prone due to argument matching with the generic format function, and should instead use named arguments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread R/format.R
Comment on lines +484 to +497
format.parameters_pca <- function(x, labels = NULL, threshold = NULL, ...) {
# Labels
if (!is.null(labels)) {
x$Label <- labels
x <- x[c("Variable", "Label", names(x)[!names(x) %in% c("Variable", "Label")])]
}

# Replace by NA all cells below threshold
if (!is.null(threshold)) {
x <- .filter_loadings(x, threshold = threshold)
}

x
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The sort argument and its corresponding sorting logic were removed from .print_parameters_cfa_efa but are not implemented in format.parameters_pca. As a result, calling print(..., sort = TRUE) will now silently ignore the sorting request.

To fix this, we should add the sort argument to format.parameters_pca and apply .sort_loadings(x) when sort = TRUE.

format.parameters_pca <- function(x, labels = NULL, threshold = NULL, sort = FALSE, ...) {
  # Sorting
  if (isTRUE(sort)) {
    x <- .sort_loadings(x)
  }

  # Labels
  if (!is.null(labels)) {
    x$Label <- labels
    x <- x[c("Variable", "Label", names(x)[!names(x) %in% c("Variable", "Label")])]
  }

  # Replace by NA all cells below threshold
  if (!is.null(threshold)) {
    x <- .filter_loadings(x, threshold = threshold)
  }

  x
}

Comment thread R/utils_pca_efa.R Outdated
Comment on lines +418 to +419
# formatting
x <- format(x, labels, threshold, ...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Calling format(x, labels, threshold, ...) with positional arguments is highly error-prone because format is a standard R generic with formal arguments trim, digits, nsmall, justify, width, and na.encode before ....

Passing labels and threshold positionally will cause them to be matched to trim and digits of the generic format, meaning they will never reach the labels and threshold arguments of format.parameters_pca.

Additionally, we need to explicitly pass sort = sort to ensure the sorting logic is executed.

  # formatting
  x <- format(x, labels = labels, threshold = threshold, sort = sort, ...)

@strengejacke
strengejacke merged commit fbd5a50 into main Jun 28, 2026
9 of 20 checks passed
@strengejacke
strengejacke deleted the strengejacke/issue1234 branch June 28, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add format() method to parameters_efa objects

1 participant