From f85813970921b37d1bc1c426390b5d4d8d763abc Mon Sep 17 00:00:00 2001 From: Julius Pfadt Date: Wed, 16 Oct 2024 13:05:44 +0200 Subject: [PATCH] fix some more errors Frantisek found --- R/confirmatoryfactoranalysis.R | 9 +++++---- R/exploratoryfactoranalysis.R | 6 ++---- R/principalcomponentanalysis.R | 16 ++++++++-------- inst/qml/ExploratoryFactorAnalysis.qml | 2 ++ inst/qml/PrincipalComponentAnalysis.qml | 1 + 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/R/confirmatoryfactoranalysis.R b/R/confirmatoryfactoranalysis.R index 827f7cd..c7581f8 100644 --- a/R/confirmatoryfactoranalysis.R +++ b/R/confirmatoryfactoranalysis.R @@ -164,7 +164,9 @@ confirmatoryFactorAnalysisInternal <- function(jaspResults, dataset, options, .. return(dataset) } - if (!isSymmetric(as.matrix(dataset))) .quitAnalysis(gettext("Input data does not seem to be a symmetric matrix! Please check the format of the input data.")) + dtmp <- as.matrix(dataset) + colnames(dtmp) <- NULL # otherwise isSymmetric complains + if (!isSymmetric(as.matrix(dtmp))) .quitAnalysis(gettext("Input data does not seem to be a symmetric matrix! Please check the format of the input data.")) vars <- unlist(lapply(options[["factors"]], `[[`, "indicators"), use.names = FALSE) @@ -175,9 +177,8 @@ confirmatoryFactorAnalysisInternal <- function(jaspResults, dataset, options, .. usedvars <- vars[!duplicateVars] var_idx <- match(usedvars, colnames(dataset)) mat <- try(as.matrix(dataset[var_idx, var_idx])) - if (inherits(mat, "try-error") || any(is.na(mat))) - .quitAnalysis(gettext("Input data does not seem to be a covariance matrix! Please check the format of the input data. - All cells must be numeric, and the number of rows must equal the number of columns.")) + if (inherits(mat, "try-error")) + .quitAnalysis(gettext("All cells must be numeric.")) if (options[["group"]] != "") .quitAnalysis(gettext("Grouping variable not supported for covariance matrix input")) diff --git a/R/exploratoryfactoranalysis.R b/R/exploratoryfactoranalysis.R index 1bf84bc..c33f255 100644 --- a/R/exploratoryfactoranalysis.R +++ b/R/exploratoryfactoranalysis.R @@ -215,10 +215,8 @@ exploratoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ... # I can use stop() because it's caught by the try and the message is put on # on the modelcontainer. if (ncomp == 0) - stop( - gettext("No factors with an eigenvalue > "), options$eigenValuesBox, ". ", - gettext("Maximum observed eigenvalue equals "), round(max(parallelResult$fa.values), 3) - ) + .quitAnalysis( gettextf("No factors with an eigenvalue > %1$s. Maximum observed eigenvalue equals %2$s.", + options$eigenValuesAbove, round(max(parallelResult$fa.values), 3))) return(ncomp) } } diff --git a/R/principalcomponentanalysis.R b/R/principalcomponentanalysis.R index 2872f52..2a7b81b 100644 --- a/R/principalcomponentanalysis.R +++ b/R/principalcomponentanalysis.R @@ -75,14 +75,16 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, .. return(dataset) } - if (!isSymmetric(as.matrix(dataset))) .quitAnalysis(gettext("Input data does not seem to be a symmetric matrix! Please check the format of the input data.")) + dtmp <- as.matrix(dataset) + colnames(dtmp) <- NULL # otherwise isSymmetric complains + if (!isSymmetric(as.matrix(dtmp))) .quitAnalysis(gettext("Input data does not seem to be a symmetric matrix! Please check the format of the input data.")) usedvars <- unlist(options[["variables"]]) var_idx <- match(usedvars, colnames(dataset)) mat <- try(as.matrix(dataset[var_idx, var_idx])) - if (inherits(mat, "try-error") || any(is.na(mat))) - .quitAnalysis("Input data does not seem to be a covariance matrix! Please check the format of the input data. - All cells must be numeric, and the number of rows must equal the number of columns.") + if (inherits(mat, "try-error")) + .quitAnalysis(gettext("All cells must be numeric.")) + .hasErrors(mat, type = "varCovMatrix", message='default', exitAnalysisIfErrors = TRUE) colnames(mat) <- rownames(mat) <- colnames(dataset)[var_idx] @@ -261,10 +263,8 @@ principalComponentAnalysisInternal <- function(jaspResults, dataset, options, .. # I can use stop() because it's caught by the try and the message is put on # on the modelcontainer. if (ncomp == 0) - stop( - gettext("No components with an eigenvalue > "), options$eigenValuesBox, ". ", - gettext("Maximum observed eigenvalue equals "), round(max(parallelResult$pc.values), 3) - ) + .quitAnalysis( gettextf("No factors with an eigenvalue > %1$s. Maximum observed eigenvalue equals %2$s.", + options$eigenValuesAbove, round(max(parallelResult$fa.values), 3))) return(ncomp) } diff --git a/inst/qml/ExploratoryFactorAnalysis.qml b/inst/qml/ExploratoryFactorAnalysis.qml index e055a04..272384c 100644 --- a/inst/qml/ExploratoryFactorAnalysis.qml +++ b/inst/qml/ExploratoryFactorAnalysis.qml @@ -109,6 +109,8 @@ Form label: qsTr("Number of factors") defaultValue: 1 min: 1 + max: variables.count > 1 ? variables.count : 1 + } } } diff --git a/inst/qml/PrincipalComponentAnalysis.qml b/inst/qml/PrincipalComponentAnalysis.qml index 88456bb..fadabaa 100644 --- a/inst/qml/PrincipalComponentAnalysis.qml +++ b/inst/qml/PrincipalComponentAnalysis.qml @@ -105,6 +105,7 @@ Form label: qsTr("Number of components") defaultValue: 1 min: 1 + max: variables.count > 1 ? variables.count : 1 } } }