Skip to content

Commit 6733add

Browse files
committed
updating documentation
1 parent b680887 commit 6733add

24 files changed

+106
-63
lines changed

R/categorical.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ cat_var_name <- function(x, infix=INFIX_CAT_NAME){
8888
gsub(suffix,"",names(x$a))
8989
}
9090

91-
#' Check if rules are categorical
91+
#' Check whether rules are categorical
9292
#'
93-
#' Check if rules are categorical
93+
#' Check whether rules are categorical
9494
#' @export
9595
#' @param x validator object
9696
#' @param ... not used

R/conditional.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ is_condition_ <- function(expr, or=TRUE, top=TRUE, ...){
2323
)
2424
}
2525

26-
#' Check if rules are conditional rules
26+
#' Check whether rules are conditional rules
2727
#'
28-
#' Check if rules are conditional rules
28+
#' Check whether rules are conditional rules
2929
#' @export
3030
#' @param rules validator object containing validation rules
3131
#' @param ... not used

R/detect_boundary.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#' Detect the range for numerical variables
1+
#' Detect the allowed range for numerical variables
22
#'
3-
#' Detect for each numerical variable in a validation rule set, what its maximum and minimum values are.
3+
#' Detect for each numerical variable in a validation rule set, what its maximum and minimum allowed values are.
4+
#' The rule set may constrain numerical variables to a subset of their values.
45
#' This allows for manual rule set checking: does rule set `x` overly constrain numerical values?
56
#'
67
#' This procedure only finds minimum and maximum values, but misses gaps.
@@ -60,8 +61,8 @@ detect_boundary_num <- function(x, eps = 1e-8, ...){
6061

6162
#' Detect domains for categorical variables
6263
#'
63-
#' Detect viable domains for categorical variables.
64-
#' A rule set may constrain a categorical variable to a subset of its values.
64+
#' Detect the allowed values for categorical variables: the rule set may constrain
65+
#' the categorical variables to a subset of their values.
6566
#' `detect_boundary_cat()` finds the categories that are allowed by the rule set.
6667
#' @example ./examples/detect_boundary.R
6768
#' @param x [validate::validator()] object with rules

R/detect_contradicting_if_rules.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#' Detect contradictory if-rules
22
#'
3-
#' Detect whether conditions in if-rules may generate contradictions. Strictly
3+
#' Detect whether conditions in conditional if-rules may generate contradictions. Strictly
44
#' speaking these rules do not make the rule set infeasible but rather make
55
#' the if-condition unsatisfiable.
66
#' Semantically speaking these rules are
77
#' contradicting, because the writer of the rule set did not have the intention
88
#' to make the condition forbidden.
99
#'
10-
#' In general it detects cases where:
10+
#' In general it detects (variations on) cases where:
1111
#'
12-
#' - `if (A) B` and `if (A) !B`, which probably is not intended, but strictly speaking equals `!A`.
13-
#' - `if (A) B` and `if (B) !A`, which probably is not intended but strictly speaking equals `!A`.
12+
#' - `if (A) B` and `if (A) !B`, which probably is not intended, but logically equals `!A`.
13+
#' - `if (A) B` and `if (B) !A`, which probably is not intended but logically equals `!A`.
1414
#'
1515
#' See examples for more details.
1616
#'
@@ -83,7 +83,7 @@ check_condition <- function(cond_expr, x){
8383
for (i in seq_along(cond)){
8484
cd <- cond[-i]
8585
v <- x + do.call(validate::validator, cd)
86-
if (is_feasible(v)){
86+
if (is_feasible(v, verbose=FALSE)){
8787
next
8888
}
8989
v1 <- is_contradicted_by(v, names(cd), verbose = FALSE)

R/detect_fixed_variables.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#'
33
#' Detects variables that are constrained by the rule set to have one fixed value.
44
#' To simplify a rule set, these variables can be substituted with their value.
5+
#' See examples.
56
#' @example ./examples/detect_fixed_variables.R
67
#' @seealso [simplify_fixed_variables()]
78
#' @param x [validate::validator()] object with the validation rules.

R/feasible.R

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
11
#' Check the feasibility of a rule set
22
#'
33
#' An infeasible rule set cannot be satisfied by any data because of internal
4-
#' contradictions. This function checks whether the record-wise linear,
4+
#' contradictions: the combination of the rules make it inconsistent.
5+
#' This function checks whether the record-wise linear,
56
#' categorical and conditional rules in a rule set are consistent.
6-
#' Note that is it always wise to also check `detect_contradicting_if_rules()`.
7+
#' Note that is it wise to also check `detect_contradicting_if_rules()`:
8+
#' conditional If-rules
9+
#' may not be strictly inconsistent, but can be semantically inconsistent.
710
#'
811
#' @example ./examples/feasible.R
912
#' @param x `validator` object with validation rules.
1013
#' @param ... not used
14+
#' @param verbose if `TRUE` print information to the console
1115
#' @family feasibility
1216
#' @return TRUE or FALSE
1317
#' @export
14-
is_infeasible <- function(x, ...){
18+
is_infeasible <- function(x, ..., verbose = interactive()){
1519
lp <- to_lp(x) # TODO find out how to treat eps for linear inequalities...
1620
lpSolveAPI::lp.control(lp, presolve="rows", break.at.first = TRUE)
1721
res <- solve(lp)
1822
# any of the following means that there is a solution found by lpSolveAPI:
1923
# TODO generate errors if the lpSolveAPI gives other return values...
20-
!(res %in% c(0,1,4,12))
24+
i <- !(res %in% c(0,1,4,12))
25+
26+
if (isTRUE(verbose)){
27+
if (i){
28+
message(
29+
"The rule set is infeasible:\n",
30+
" use `detect_infeasible_rules()` and `is_contradicted_by` to find out\n",
31+
" which rules are causing infeasibility.",
32+
" or `make_feasible()` to make the rule set feasible."
33+
)
34+
} else {
35+
message(
36+
"The rule set is feasible,\n",
37+
" but may contain contradictions in conditional if-rules.\n",
38+
" use `detect_contradicting_if_rules()` to find out whether there are \n",
39+
" contradictions in the if-clauses."
40+
)
41+
}
42+
}
43+
44+
i
2145
}
2246

2347
is_feasible <- function(x, ...){
@@ -70,7 +94,7 @@ make_feasible <- function(x, ..., verbose = interactive()){
7094
#' @return `character` with the names of the rules that are causing infeasibility.
7195
detect_infeasible_rules <- function(x, weight = numeric(), ..., verbose = interactive()){
7296
# browser()
73-
if (!is_infeasible(x)){
97+
if (!is_infeasible(x, verbose=FALSE)){
7498
return(character())
7599
}
76100
# browser()

R/implied_by.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#' Find which rule(s) make rule_name redundant
1+
#' Find which rule(s) imply a rule
22
#'
33
#' Find out which rules are causing rule_name(s) to be redundant.
4+
#' A rule set can contain rules that are implied by the other rules, so it is
5+
#' superfluous, see examples.
46
#' @example ./examples/redundancy.R
57
#' @export
68
#' @param x [validate::validator()] object with rule

R/redundancy.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#' Detect redundancies in a rule set, but do not remove the rules.
44
#' A rule in a ruleset can be redundant if it is implied by another rule
55
#' or by a combination of rules. See the examples for more information.
6-
#'
76
#' @note For removal of duplicate rules, simplify
87
#' @example ./examples/redundancy.R
98
#' @param x [validate::validator()] object with the validation rules.
@@ -91,7 +90,7 @@ is_redundant <- function(dnf_set, i, ...){
9190
# print(get(n))
9291
# }
9392
# }
94-
is_infeasible(test_rules)
93+
is_infeasible(test_rules, verbose = FALSE)
9594
}
9695

9796
# x <- validator( rule1 = x > 1

R/simplify_conditional.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#' Simplify conditional statements
22
#'
3-
#' Conditional rules may be constrained by the others rules in a validation rule set.
3+
#' Conditional rules (if-rules) may be constrained by the others rules in a validation rule set.
44
#' This procedure tries to simplify conditional statements.
5-
#'
6-
#'
75
#' @references TODO non-constraining, non-relaxing
86
#' @example ./examples/simplify_conditional.R
97
#' @export
@@ -31,7 +29,7 @@ simplify_non_relaxing <- function(cond_expr, vals){
3129
clauses <- as_dnf(cond_expr)
3230
clauses[] <- lapply(clauses, function(clause){
3331
test_rules <- do.call(validate::validator, c(vals, clause))
34-
if (is_infeasible(test_rules)){
32+
if (is_infeasible(test_rules, verbose=FALSE)){
3533
return(NULL)
3634
}
3735
clause
@@ -45,7 +43,7 @@ simplify_non_constraining <- function(cond_expr, vals){
4543
for (clause in clauses){
4644
clause_neg <- invert_or_negate(clause)
4745
test_rules <- do.call(validate::validator, c(vals, clause_neg))
48-
if (is_infeasible(test_rules)){
46+
if (is_infeasible(test_rules, verbose=FALSE)){
4947
return(clause)
5048
}
5149
}

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ check_validator <- function(x, copy = TRUE, check_infeasible = TRUE){
33
if (!inherits(x, "validator")){
44
stop("This method needs a 'validator' object, but was given a '", class(x), "'.",call. = FALSE)
55
}
6-
if (isTRUE(check_infeasible) && is_infeasible(x)){
6+
if (isTRUE(check_infeasible) && is_infeasible(x, verbose=FALSE)){
77
stop("This rule set is infeasible. Please fix and repair the rule set with `make_feasible` before continuing.", call. = FALSE)
88
}
99
invisible(x)

0 commit comments

Comments
 (0)