Skip to content

Commit dec5c3f

Browse files
committed
made the detect_contradicting_if_rules more general
1 parent ecb0850 commit dec5c3f

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

R/detect_contradicting_if_rules.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,23 @@ check_condition <- function(cond_expr, x){
7373
if (length(clauses) <= 1){
7474
return(NULL)
7575
}
76-
# browser()
77-
# take last clause as consequent, and the rest as the condition
78-
cond <-
79-
utils::head(clauses, -1) |>
80-
lapply(invert_or_negate)
81-
76+
# browser()
77+
cond <- lapply(clauses, invert_or_negate)
8278
names(cond) <- paste0(".test", seq_along(cond))
83-
cond_s <- sapply(cond, deparse_all) |> paste0(collapse = " && ")
79+
cond_s <- sapply(cond, deparse_all)
8480

85-
v <- x + do.call(validate::validator, cond)
86-
if (is_feasible(v)){
87-
return(NULL)
88-
}
8981
l <- list()
90-
v1 <- is_contradicted_by(v, names(cond), verbose = FALSE)
91-
l[[cond_s]] <- v1
82+
83+
for (i in seq_along(cond)){
84+
cd <- cond[-i]
85+
v <- x + do.call(validate::validator, cd)
86+
if (is_feasible(v)){
87+
next
88+
}
89+
v1 <- is_contradicted_by(v, names(cd), verbose = FALSE)
90+
c_s <- paste0(cond_s[-i], collapse = " && ")
91+
l[[c_s]] <- v1
92+
}
93+
9294
l
9395
}

R/simplify_conditional.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#' Conditional rules may be constrained by the others rules in a validation rule set.
44
#' This procedure tries to simplify conditional statements.
55
#'
6+
#'
67
#' @references TODO non-constraining, non-relaxing
78
#' @example ./examples/simplify_conditional.R
89
#' @export

man/detect_redundancy.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/is_implied_by.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/remove_redundancy.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)