Skip to content

Commit 6de6cf4

Browse files
committed
save attr
1 parent 71e19a1 commit 6de6cf4

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

R/factor_analysis.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ factor_analysis.data.frame <- function(x,
6060
)
6161

6262
attr(out, "dataset") <- x
63+
attr(out, "reverse_items") <- reverse_items
6364
out
6465
}
6566

R/principal_components.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ principal_components.data.frame <- function(x,
465465
)
466466
attr(pca_loadings, "data") <- data_name
467467
attr(pca_loadings, "dataset") <- original_data
468+
attr(pca_loadings, "reverse_items") <- reverse_items
468469

469470
# add class-attribute for printing
470471
class(pca_loadings) <- unique(c("parameters_pca", "see_parameters_pca", class(pca_loadings)))

R/utils_pca_efa.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ get_scores <- function(x, n_items = NULL, reverse_items = NULL, verbose = TRUE)
5858

5959
# should some items be reversed?
6060
if (!is.null(reverse_items)) {
61+
# check if the object has an attribute "reverse_items" - if so, warn that
62+
# we don't want to "double reverse" items
63+
if ("reverse_items" %in% names(attributes(dataset))) {
64+
insight::format_warning(
65+
"It seem that items have already been reversed in this data set. Make sure that you do not reverse them again."
66+
)
67+
}
6168
# numeric indices should be replaced by their column names
6269
if (is.numeric(reverse_items)) {
6370
reverse_items <- colnames(dataset)[reverse_items]

0 commit comments

Comments
 (0)