From fd3810226148022165be084fd8745db7ca34fb8e Mon Sep 17 00:00:00 2001 From: maltelueken Date: Mon, 30 Oct 2023 10:27:16 +0100 Subject: [PATCH] Fix error handling --- R/classicProcess.R | 47 +++++++++++++------ ...test-classic-process-integration-general.R | 44 +++++++++++++++++ 2 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 tests/testthat/test-classic-process-integration-general.R diff --git a/R/classicProcess.R b/R/classicProcess.R index 5a34142..5fd5e59 100644 --- a/R/classicProcess.R +++ b/R/classicProcess.R @@ -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 @@ -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) { diff --git a/tests/testthat/test-classic-process-integration-general.R b/tests/testthat/test-classic-process-integration-general.R new file mode 100644 index 0000000..e51091b --- /dev/null +++ b/tests/testthat/test-classic-process-integration-general.R @@ -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") +})