Skip to content

Commit 59f46e3

Browse files
committed
tests
1 parent 6de6cf4 commit 59f46e3

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

R/principal_components.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ principal_components.data.frame <- function(x,
318318
}
319319
# reverse the items
320320
x <- datawizard::reverse_scale(x, reverse_items, verbose = verbose)
321+
original_data <- datawizard::reverse_scale(original_data, reverse_items, verbose = FALSE)
321322
}
322323

323324
# Select numeric only
@@ -343,6 +344,9 @@ principal_components.data.frame <- function(x,
343344
)
344345

345346
attr(pca_loadings, "data") <- data_name
347+
attr(pca_loadings, "dataset") <- original_data
348+
attr(pca_loadings, "reverse_items") <- reverse_items
349+
346350
return(pca_loadings)
347351
}
348352

R/utils_pca_efa.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ get_scores <- function(x, n_items = NULL, reverse_items = NULL, verbose = TRUE)
6060
if (!is.null(reverse_items)) {
6161
# check if the object has an attribute "reverse_items" - if so, warn that
6262
# we don't want to "double reverse" items
63-
if ("reverse_items" %in% names(attributes(dataset))) {
63+
if ("reverse_items" %in% names(attributes(x))) {
6464
insight::format_warning(
6565
"It seem that items have already been reversed in this data set. Make sure that you do not reverse them again."
6666
)

tests/testthat/test-get_scores.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,16 @@ test_that("get_scores", {
2525

2626
expect_silent(get_scores(pca, reverse_items = c("cyl", "abc"), verbose = FALSE))
2727
expect_silent(get_scores(pca, reverse_items = c("cyl", "drat"), verbose = FALSE))
28+
29+
pca <- principal_components(
30+
mtcars[, 1:7],
31+
n = 2,
32+
rotation = "varimax",
33+
reverse_items = c("cyl", "drat")
34+
)
35+
expect_warning(
36+
get_scores(pca, reverse_items = c("cyl", "drat")),
37+
regex = "It seems that",
38+
fixed = TRUE
39+
)
2840
})

0 commit comments

Comments
 (0)