Skip to content

Commit

Permalink
Fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
maltelueken committed Oct 30, 2023
1 parent 2c349f0 commit fd38102
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 14 deletions.
47 changes: 33 additions & 14 deletions R/classicProcess.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
ClassicProcess <- function(jaspResults, dataset = NULL, options) {
# Set title
jaspResults$title <- gettext("Process Analysis")

# Check if all models are ready to compute something
ready <- .procIsReady(options)

if (!ready) return()
# Check if analysis has any variables to read in
if (options[["dependent"]] == "" || (length(options[["covariates"]]) == 0 && length(options[["factors"]]) == 0)) {
return()
}
# Read dataset
dataset <- .procReadData(options)
# Check for errors in dataset
ready <- .procErrorHandling(dataset, options)
.procErrorHandling(dataset, options)
# Check if all models are ready to compute something
if (!.procIsReady(options)) return()
# Create a container for each model
.procContainerModels(jaspResults, options)
# Transform input for each model into a graph for further processing
Expand Down Expand Up @@ -544,14 +545,32 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
}

.procErrorHandling <- function(dataset, options) {
# See error handling
vars <- lapply(.procGetDependencies(), function(x) options[[x]])
.hasErrors(dataset, "run", type = c('observations', 'variance', 'infinity'),
all.target = vars,
observations.amount = '< 2',
exitAnalysisIfErrors = TRUE)

return(TRUE)
.hasErrors(dataset, "run",
type = c('observations', 'variance', 'infinity'),
observations.target = c(
options[["dependent"]],
options[["covariates"]],
options[["factors"]]
),
observations.amount = '< 2',
variance.target = c(
options[["dependent"]],
options[["covariates"]]
),
infinity.target = c(
options[["dependent"]],
options[["covariates"]]
),
exitAnalysisIfErrors = TRUE
)
if (length(options[["covariates"]]) > 0) {
.hasErrors(dataset, "run",
type = "varCovData",
varCovData.target = options[["covariates"]],
varCovData.corFun = stats::cov,
exitAnalysisIfErrors = TRUE
)
}
}

.procModProbes <- function(jaspResults, dataset, options) {
Expand Down
44 changes: 44 additions & 0 deletions tests/testthat/test-classic-process-integration-general.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# General integration tests for Classic Process analysis

test_that("Error handling works - observations", {
options <- jaspTools::analysisOptions("ClassicProcess")
options$dependent <- "contNormal"
options$covariates <- list("debNaN")
set.seed(1)
results <- jaspTools::runAnalysis("ClassicProcess", "debug", options)
expect_identical(results[["status"]], "validationError", label = "Observations check")

options <- jaspTools::analysisOptions("ClassicProcess")
options$dependent <- "contNormal"
options$factors <- list("debNaN")
set.seed(1)
results <- jaspTools::runAnalysis("ClassicProcess", "debug", options)
expect_identical(results[["status"]], "validationError", label = "Observations check")
})

test_that("Error handling works - variance", {
options <- jaspTools::analysisOptions("ClassicProcess")
options$dependent <- "contNormal"
options$covariates <- list("debSame")
set.seed(1)
results <- jaspTools::runAnalysis("ClassicProcess", "debug", options)
expect_identical(results[["status"]], "validationError", label = "Variance check")
})

test_that("Error handling works - infinity", {
options <- jaspTools::analysisOptions("ClassicProcess")
options$dependent <- "contNormal"
options$covariates <- list("debInf")
set.seed(1)
results <- jaspTools::runAnalysis("ClassicProcess", "debug", options)
expect_identical(results[["status"]], "validationError", label = "Infinity check")
})

test_that("Error handling works - covariance", {
options <- jaspTools::analysisOptions("ClassicProcess")
options$dependent <- "contNormal"
options$covariates <- list("debCollin1", "debCollin2")
set.seed(1)
results <- jaspTools::runAnalysis("ClassicProcess", "debug", options)
expect_identical(results[["status"]], "validationError", label = "Covariance check")
})

0 comments on commit fd38102

Please sign in to comment.