Skip to content

Commit ecb0850

Browse files
committed
added verbose argument implied_by
1 parent 4810edb commit ecb0850

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

R/implied_by.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#' @param x [validate::validator()] object with rule
77
#' @param rule_name `character` with the names of the rules to be checked
88
#' @param ... not used
9+
#' @param verbose if `TRUE` print information to the console
910
#' @family redundancy
1011
#' @return `character` with the names of the rule that cause the implication.
11-
is_implied_by <- function(x, rule_name, ...){
12+
is_implied_by <- function(x, rule_name, ..., verbose = interactive()){
1213
check_validator(x)
1314
idx <- match(rule_name, names(x), 0)
1415
if (any(idx == 0L)){
@@ -41,7 +42,18 @@ is_implied_by <- function(x, rule_name, ...){
4142
# names(weight) <- names(negated_rules)
4243
# detect_infeasible_rules(test_rules, weight)
4344

44-
is_contradicted_by(test_rules, names(negated_rules), verbose = FALSE)
45+
res <- is_contradicted_by(test_rules, names(negated_rules), verbose = FALSE)
46+
if (isTRUE(verbose) && length(res)){
47+
v <- x[rule_name] |> to_exprs() |> lapply(deparse_all)
48+
v_i <- x[res] |> to_exprs() |> lapply(deparse_all)
49+
message(
50+
"Rule(s)\n",
51+
paste0(" ", names(v),": ", v, collapse = "\n"),
52+
"\nimplied by:\n",
53+
paste0(" ", names(v_i),": ", v_i, collapse = "\n")
54+
)
55+
}
56+
res
4557
}
4658

4759
# rules <- x <- validator(r1 = x > 1, r2 = x > 2)

examples/redundancy.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ rules <- validator( rule1 = x > 1
66
remove_redundancy(rules, verbose=TRUE)
77

88
# rule 1 is implied by rule 2
9-
is_implied_by(rules, "rule1")
9+
is_implied_by(rules, "rule1", verbose=TRUE)
1010

1111
rules <- validator( rule1 = x > 2
1212
, rule2 = x > 2

0 commit comments

Comments
 (0)