From 351e0408d61e168bd3d04f667e0ac9d423ca621f Mon Sep 17 00:00:00 2001 From: Koen Derks Date: Mon, 14 Oct 2024 17:54:33 +0200 Subject: [PATCH] Data handling updates (#145) * Only sem is problematic * use anyNA instead of any(is.na()) --- R/bainCommon.R | 28 +++++++++++----------------- inst/Description.qml | 2 ++ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/R/bainCommon.R b/R/bainCommon.R index 9d30763..4dc42d0 100644 --- a/R/bainCommon.R +++ b/R/bainCommon.R @@ -52,28 +52,22 @@ vars <- c(numerics, factors) if (type != "sem") { - if (is.null(dataset)) { - trydata <- .readDataSetToEnd(columns.as.numeric = numerics, columns.as.factor = factors) - missing <- names(which(apply(trydata, 2, function(x) { - any(is.na(x)) - }))) - if (type == "onesampleTTest") { # For the one sample t test we do not remove the NA's listwise - dataset <- .readDataSetToEnd(columns.as.numeric = numerics, columns.as.factor = factors) - } else { - dataset <- .readDataSetToEnd(columns.as.numeric = numerics, columns.as.factor = factors, exclude.na.listwise = vars) - } - if ((type == "anova" || type == "ancova") && options[["fixedFactors"]] != "") { - if (any(grepl(pattern = " ", x = levels(dataset[, options[["fixedFactors"]]])))) { - jaspBase:::.quitAnalysis(gettext("Bain does not accept factor levels that contain spaces. Please remove the spaces from your factor levels to continue.")) - } + dataset[factors] <- lapply(dataset[factors], as.factor) + missing <- names(which(apply(dataset, 2, function(x) { + anyNA(x) + }))) + if (type != "onesampleTTest") { + dataset <- jaspBase::excludeNaListwise(dataset, vars) + } + if ((type == "anova" || type == "ancova") && options[["fixedFactors"]] != "") { + if (any(grepl(pattern = " ", x = base::levels(dataset[, options[["fixedFactors"]]])))) { + jaspBase:::.quitAnalysis(gettext("Bain does not accept factor levels that contain spaces. Please remove the spaces from your factor levels to continue.")) } - } else { - dataset <- .vdf(dataset, columns.as.numeric = numerics, columns.as.factor = factors) } } else { trydata <- .readDataSetToEnd(all.columns = TRUE) missing <- names(which(apply(trydata, 2, function(x) { - any(is.na(x)) + anyNA(x) }))) dataset <- .readDataSetToEnd(all.columns = TRUE, exclude.na.listwise = .bainSemGetUsedVars(options[["syntax"]]$model, colnames(trydata))) } diff --git a/inst/Description.qml b/inst/Description.qml index 5c696e9..da51f45 100755 --- a/inst/Description.qml +++ b/inst/Description.qml @@ -14,6 +14,7 @@ Description website : "www.informative-hypotheses.sites.uu.nl/software/bain/" license : "GPL (>= 3)" hasWrappers : true + preloadData : true GroupTitle { @@ -73,5 +74,6 @@ Description menu: "Structural Equation Modeling" title: "Bain Structural Equation Modeling" func: "BainSemBayesian" + preloadData: false } }