diff --git a/R/cohort_methods.R b/R/cohort_methods.R index 72eba17..53c5181 100644 --- a/R/cohort_methods.R +++ b/R/cohort_methods.R @@ -225,9 +225,12 @@ Cohort <- R6::R6Class( filter_env[[param_name]] <- new_val } } - if (!missing(active)) { - filter_env[["active"]] <- active + if(!is.logical(active)) { + warning("Active accepts only logical values.") + } else { + filter_env[["active"]] <- active + } } if (run_flow && (!missing(active) || any_changed)) { @@ -456,6 +459,11 @@ Cohort <- R6::R6Class( if (state == "pre") { data_id <- prev_step(step_id) } + + if(is.null(self$get_step(step_id)) && step_id != 0){ + stop("Step is not exist in this cohort object.") + } + if (missing(filter_id)) { return( .get_stats(private$source, private$data_objects[[data_id]]) diff --git a/tests/testthat/test-cohort_methods.R b/tests/testthat/test-cohort_methods.R index 1d02949..503ec87 100644 --- a/tests/testthat/test-cohort_methods.R +++ b/tests/testthat/test-cohort_methods.R @@ -492,6 +492,11 @@ test_that("Updating filter works fine", { label = "Cannot modify filter ‘type’, ‘id’, ‘name’ parameters." ) + expect_warning( + coh$update_filter(1L, "sepal_l", active = "FALSE"), + regexp = "Active accepts only logical values." + ) + # Using S3 Cohort methods coh <- cohort( set_source( @@ -515,6 +520,11 @@ test_that("Updating filter works fine", { coh$update_filter(1L, "sepal_l", type = "discrete"), label = "Cannot modify filter ‘type’, ‘id’, ‘name’ parameters." ) + + expect_warning( + coh$update_filter(1L, "sepal_l", active = "FALSE"), + regexp = "Active accepts only logical values." + ) }) test_that("Updating source works fine", { @@ -632,6 +642,11 @@ test_that("Getting filter stats works fine", { as.list(table(iris$Species[iris$Species %in% c("setosa", "virginica")])) ) + expect_error( + stat(coh,10), + regexp = "Step is not exist in this cohort object." + ) + # Using S3 Cohort methods coh <- cohort( set_source(