Skip to content

Commit 9b6b542

Browse files
committed
Add test for reverse_items
1 parent 256e474 commit 9b6b542

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: parameters
33
Title: Processing of Model Parameters
4-
Version: 0.26.0.10
4+
Version: 0.26.0.11
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",

R/utils_pca_efa.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#' indicating their column positions in `x` that should be reversed before
1818
#' computing sum scores. This is useful when the items are not coded in the same
1919
#' direction. If `NULL` (default), no items are reversed.
20+
#' @param verbose Logical, whether to print messages about reversing items.
2021
#'
2122
#' @details
2223
#' `get_scores()` takes the results from [`principal_components()`] or
@@ -51,7 +52,7 @@
5152
#' (mtcars$hp + mtcars$qsec) / 2
5253
#'
5354
#' @export
54-
get_scores <- function(x, n_items = NULL, reverse_items = NULL) {
55+
get_scores <- function(x, n_items = NULL, reverse_items = NULL, verbose = TRUE) {
5556
subscales <- closest_component(x)
5657
dataset <- attributes(x)$dataset
5758

man/get_scores.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-get_scores.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ test_that("get_scores", {
66
scores <- get_scores(pca)
77
expect_equal(head(scores$Component_1), c(38.704, 38.755, 28.194, 58.339, 78.658, 51.064), tolerance = 1e-2)
88
expect_equal(head(scores$Component_2), c(63.23, 63.51, 55.805, 64.72, 96.01, 62.61), tolerance = 1e-2)
9+
10+
scores2 <- get_scores(pca, reverse_items = c("cyl", "drat"))
11+
expect_equal(head(scores2$Component_1), c(38.682, 38.733, 28.992, 58.645, 78.136, 51.498), tolerance = 1e-2)
12+
13+
expect_warning(
14+
get_scores(pca, reverse_items = c("cyl", "abc")),
15+
regex = "Following variable(s)",
16+
fixed = TRUE
17+
)
918
})

0 commit comments

Comments
 (0)