Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 27, 2022
1 parent bcc509d commit 51adc1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 4 additions & 3 deletions R/n_factors.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,16 @@ n_factors <- function(x,
nobs <- x
package <- package[!package %in% c("pcdimension", "PCDimension")]
} else if (is.matrix(x) || inherits(x, "easycormatrix")) {
stop("Please input the correlation matrix via the `cor = ...` argument and
the number of rows / observations via the first argument.")
insight::format_error(
"Please input the correlation matrix via the `cor = ...` argument and the number of rows / observations via the first argument."
)
}
} else {
nobs <- nrow(x)
}

# Get only numeric
x <- x[sapply(x, is.numeric)]
x <- x[vapply(x, is.numeric, logical(1))]

# Correlation matrix
if (is.null(cor)) {
Expand Down
5 changes: 1 addition & 4 deletions R/principal_components.R
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ principal_components.data.frame <- function(x,
x <- stats::na.omit(x)

# Select numeric only
x <- x[sapply(x, is.numeric)]
x <- x[vapply(x, is.numeric, logical(1))]

# N factors
n <- .get_n_factors(x, n = n, type = "PCA", rotation = rotation)
Expand Down Expand Up @@ -456,9 +456,6 @@ principal_components.data.frame <- function(x,

# rotate loadings
insight::check_if_installed("psych", reason = sprintf("`%s`-rotation.", rotation))
if (!requireNamespace("psych", quietly = TRUE)) {
insight::format_error(sprintf("Package `psych` required for `%s`-rotation.", rotation))
}

pca <- psych::principal(x, nfactors = n, rotate = rotation, ...)
msa <- psych::KMO(x)
Expand Down

0 comments on commit 51adc1c

Please sign in to comment.