Add format() method to parameters_efa objects - #1236
Conversation
There was a problem hiding this comment.
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.
| 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 | ||
| } |
There was a problem hiding this comment.
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
}| # formatting | ||
| x <- format(x, labels, threshold, ...) |
There was a problem hiding this comment.
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, ...)
Fixes #1234