Skip to content

Commit

Permalink
Data handling updates (#145)
Browse files Browse the repository at this point in the history
* Only sem is problematic

* use anyNA instead of any(is.na())
  • Loading branch information
koenderks authored Oct 14, 2024
1 parent 0ac9d6b commit 351e040
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
28 changes: 11 additions & 17 deletions R/bainCommon.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down
2 changes: 2 additions & 0 deletions inst/Description.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Description
website : "www.informative-hypotheses.sites.uu.nl/software/bain/"
license : "GPL (>= 3)"
hasWrappers : true
preloadData : true

GroupTitle
{
Expand Down Expand Up @@ -73,5 +74,6 @@ Description
menu: "Structural Equation Modeling"
title: "Bain Structural Equation Modeling"
func: "BainSemBayesian"
preloadData: false
}
}

0 comments on commit 351e040

Please sign in to comment.