Skip to content

Add format() method to parameters_efa objects #1234

Description

@DominiqueMakowski

Add a bit more flexibility to extract the (sorted and thresholded) loading table to be able to put in a dataframe or gt table.

fa <- parameters::factor_analysis(mtcars, n = 5, sort = TRUE, threshold = 0.5)
#> Loading required namespace: GPArotation
as.data.frame(fa)
#>    Variable         MR4         MR1         MR3         MR2          MR5
#> 1        am  0.92878193 -0.02904994 -0.19242678 -0.08606709  0.002076381
#> 2      gear  0.80941507 -0.06332083  0.11030802  0.27207892  0.078239895
#> 3      drat  0.69349895 -0.11008263  0.14310455  0.03083509 -0.075198695
#> 4       cyl -0.49973828  0.07983766 -0.43461467  0.14865306  0.235111534
#> 5       mpg  0.43016971 -0.30236889  0.13469055 -0.31218141 -0.136169137
#> 6        wt -0.06575367  0.94128702  0.03169416  0.11324153 -0.054988569
#> 7      disp -0.07429773  0.70452626 -0.18184961 -0.15932921  0.309316866
#> 8        vs  0.04109952 -0.19522915  0.81126816 -0.09336970  0.054224969
#> 9      qsec -0.15056647  0.16132245  0.66416992 -0.17107730 -0.323890653
#> 10     carb  0.05294737  0.04917102 -0.10299756  0.89055518  0.051734879
#> 11       hp -0.04231968  0.26181482 -0.06449409  0.26692854  0.597463606
#>    Complexity  Uniqueness
#> 1    1.105625 0.138616403
#> 2    1.298485 0.155104645
#> 3    1.166648 0.285285441
#> 4    2.684933 0.038445248
#> 5    3.194961 0.131599366
#> 6    1.048112 0.001290845
#> 7    1.672600 0.038259378
#> 8    1.158377 0.129344862
#> 9    1.875171 0.096688462
#> 10   1.046991 0.016749265
#> 11   1.841725 0.046320127

Created on 2026-06-27 with reprex v2.1.1

Currently the sort and threshold are not preserved in the dataframe function, as they only affect printing.
But what if someone wants to extract the formatted table?

currently the print method calls an internal formatting method:

print.parameters_efa <- function(x,
digits = 2,
sort = FALSE,
threshold = NULL,
labels = NULL,
...) {
# extract attributes
if (is.null(threshold)) {
threshold <- attributes(x)$threshold
}
cat(.print_parameters_cfa_efa(
x,
threshold = threshold,
sort = sort,
format = "text",
digits = digits,
labels = labels,
...
))
invisible(x)
}

Defined here:

.print_parameters_cfa_efa <- function(x, threshold, sort, format, digits, labels, ...) {

My guess is that easiest option would be to add a format() or format_table() method that runs that internal formatting option and returns the result as a dataframe. what do you think?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions