diff --git a/R/col_count_match.R b/R/col_count_match.R index 1daac946b..6e5a82fe4 100644 --- a/R/col_count_match.R +++ b/R/col_count_match.R @@ -300,15 +300,11 @@ col_count_match <- function( agent <- x - if (is.null(brief)) { - - brief <- - create_autobrief( - agent = agent, - assertion_type = "col_count_match", - values = count - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + preconditions = preconditions, values = count, + assertion_type = "col_count_match" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns = "column", agent) diff --git a/R/col_exists.R b/R/col_exists.R index f56743db7..9edb8df80 100644 --- a/R/col_exists.R +++ b/R/col_exists.R @@ -278,10 +278,12 @@ col_exists <- function( agent <- x - if (is.null(brief)) { - brief <- - generate_autobriefs(agent, columns, preconditions, values, "col_exists") - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, + preconditions = preconditions, values = value, + assertion_type = "col_exists" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -309,7 +311,7 @@ col_exists <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i]], - brief = brief[i], + brief = brief[[i]], active = active ) } diff --git a/R/col_is_character.R b/R/col_is_character.R index a56ed9bd1..459ffc3b9 100644 --- a/R/col_is_character.R +++ b/R/col_is_character.R @@ -269,12 +269,12 @@ col_is_character <- function( agent <- x - if (is.null(brief)) { - brief <- - generate_autobriefs( - agent, columns, preconditions, values, "col_is_character" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, + preconditions = preconditions, values = value, + assertion_type = "col_is_character" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -302,7 +302,7 @@ col_is_character <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i]], - brief = brief[i], + brief = brief[[i]], active = active ) } diff --git a/R/col_is_date.R b/R/col_is_date.R index 5f9c91734..348901480 100644 --- a/R/col_is_date.R +++ b/R/col_is_date.R @@ -261,12 +261,12 @@ col_is_date <- function( agent <- x - if (is.null(brief)) { - brief <- - generate_autobriefs( - agent, columns, preconditions, values, "col_is_date" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, + preconditions = preconditions, values = value, + assertion_type = "col_is_date" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -294,7 +294,7 @@ col_is_date <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i]], - brief = brief[i], + brief = brief[[i]], active = active ) } diff --git a/R/col_is_factor.R b/R/col_is_factor.R index b57b724c9..325be8d7f 100644 --- a/R/col_is_factor.R +++ b/R/col_is_factor.R @@ -267,12 +267,12 @@ col_is_factor <- function( agent <- x - if (is.null(brief)) { - brief <- - generate_autobriefs( - agent, columns, preconditions, values, "col_is_factor" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, + preconditions = preconditions, values = value, + assertion_type = "col_is_factor" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -300,7 +300,7 @@ col_is_factor <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i]], - brief = brief[i], + brief = brief[[i]], active = active ) } diff --git a/R/col_is_integer.R b/R/col_is_integer.R index 9e7996d1a..b1645154c 100644 --- a/R/col_is_integer.R +++ b/R/col_is_integer.R @@ -265,12 +265,12 @@ col_is_integer <- function( agent <- x - if (is.null(brief)) { - brief <- - generate_autobriefs( - agent, columns, preconditions, values, "col_is_integer" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, + preconditions = preconditions, values = value, + assertion_type = "col_is_integer" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -298,7 +298,7 @@ col_is_integer <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i]], - brief = brief[i], + brief = brief[[i]], active = active ) } diff --git a/R/col_is_logical.R b/R/col_is_logical.R index 215d7a8f7..f9029bee0 100644 --- a/R/col_is_logical.R +++ b/R/col_is_logical.R @@ -262,12 +262,12 @@ col_is_logical <- function( agent <- x - if (is.null(brief)) { - brief <- - generate_autobriefs( - agent, columns, preconditions, values, "col_is_logical" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, + preconditions = preconditions, values = value, + assertion_type = "col_is_logical" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -295,7 +295,7 @@ col_is_logical <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i]], - brief = brief[i], + brief = brief[[i]], active = active ) } diff --git a/R/col_is_numeric.R b/R/col_is_numeric.R index b53711743..3951456a8 100644 --- a/R/col_is_numeric.R +++ b/R/col_is_numeric.R @@ -262,12 +262,12 @@ col_is_numeric <- function( agent <- x - if (is.null(brief)) { - brief <- - generate_autobriefs( - agent, columns, preconditions, values, "col_is_numeric" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, + preconditions = preconditions, values = value, + assertion_type = "col_is_numeric" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -295,7 +295,7 @@ col_is_numeric <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i]], - brief = brief[i], + brief = brief[[i]], active = active ) } diff --git a/R/col_is_posix.R b/R/col_is_posix.R index 8786163e2..aaa20af7a 100644 --- a/R/col_is_posix.R +++ b/R/col_is_posix.R @@ -262,12 +262,12 @@ col_is_posix <- function( agent <- x - if (is.null(brief)) { - brief <- - generate_autobriefs( - agent, columns, preconditions, values, "col_is_posix" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, + preconditions = preconditions, values = value, + assertion_type = "col_is_posix" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -295,7 +295,7 @@ col_is_posix <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i]], - brief = brief[i], + brief = brief[[i]], active = active ) } diff --git a/R/col_schema_match.R b/R/col_schema_match.R index 51bae99b2..cbc95c45a 100644 --- a/R/col_schema_match.R +++ b/R/col_schema_match.R @@ -356,14 +356,10 @@ col_schema_match <- function( agent <- x - if (is.null(brief)) { - - brief <- - create_autobrief( - agent = agent, - assertion_type = "col_schema_match" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + assertion_type = "col_schema_match" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns = "column", agent) diff --git a/R/col_vals_between.R b/R/col_vals_between.R index 8e21cf63e..857a21346 100644 --- a/R/col_vals_between.R +++ b/R/col_vals_between.R @@ -433,17 +433,12 @@ col_vals_between <- function( left <- as.list(left) right <- as.list(right) - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = c(left, right), - assertion_type = "col_vals_between" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = c(left, right), + assertion_type = "col_vals_between" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -480,7 +475,7 @@ col_vals_between <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_decreasing.R b/R/col_vals_decreasing.R index 3feddc6ae..1393f106d 100644 --- a/R/col_vals_decreasing.R +++ b/R/col_vals_decreasing.R @@ -413,17 +413,12 @@ col_vals_decreasing <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = increasing_tol, - assertion_type = "col_vals_decreasing" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = increasing_tol, + assertion_type = "col_vals_decreasing" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -460,7 +455,7 @@ col_vals_decreasing <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_equal.R b/R/col_vals_equal.R index a56a9a081..c30a22a48 100644 --- a/R/col_vals_equal.R +++ b/R/col_vals_equal.R @@ -365,17 +365,12 @@ col_vals_equal <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = value, - assertion_type = "col_vals_equal" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = value, + assertion_type = "col_vals_equal" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -412,7 +407,7 @@ col_vals_equal <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_expr.R b/R/col_vals_expr.R index 8c23b642a..a2d788613 100644 --- a/R/col_vals_expr.R +++ b/R/col_vals_expr.R @@ -367,14 +367,12 @@ col_vals_expr <- function( agent <- x - if (is.null(brief)) { - - brief <- - create_autobrief( - agent = agent, - assertion_type = "col_vals_expr" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + segments_list = segments_list, + preconditions = preconditions, + assertion_type = "col_vals_expr" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns = "column", agent) @@ -409,7 +407,7 @@ col_vals_expr <- function( actions = covert_actions(actions, agent), step_id = step_id, label = label[[i]], - brief = brief, + brief = brief[[i]], active = active ) } diff --git a/R/col_vals_gt.R b/R/col_vals_gt.R index 731dc219b..2f21986be 100644 --- a/R/col_vals_gt.R +++ b/R/col_vals_gt.R @@ -487,17 +487,12 @@ col_vals_gt <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = value, - assertion_type = "col_vals_gt" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = value, + assertion_type = "col_vals_gt" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -534,7 +529,7 @@ col_vals_gt <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_gte.R b/R/col_vals_gte.R index 16642ef39..3474c3bc0 100644 --- a/R/col_vals_gte.R +++ b/R/col_vals_gte.R @@ -364,17 +364,12 @@ col_vals_gte <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = value, - assertion_type = "col_vals_gte" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = value, + assertion_type = "col_vals_gte" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -411,7 +406,7 @@ col_vals_gte <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_in_set.R b/R/col_vals_in_set.R index 2a68dd114..47ac6b989 100644 --- a/R/col_vals_in_set.R +++ b/R/col_vals_in_set.R @@ -357,17 +357,12 @@ col_vals_in_set <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = set, - assertion_type = "col_vals_in_set" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = set, + assertion_type = "col_vals_in_set" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -403,7 +398,7 @@ col_vals_in_set <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_increasing.R b/R/col_vals_increasing.R index bd38c09cf..04d6c36dc 100644 --- a/R/col_vals_increasing.R +++ b/R/col_vals_increasing.R @@ -401,17 +401,12 @@ col_vals_increasing <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = decreasing_tol, - assertion_type = "col_vals_increasing" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = decreasing_tol, + assertion_type = "col_vals_increasing" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -448,7 +443,7 @@ col_vals_increasing <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_lt.R b/R/col_vals_lt.R index 85c05f186..065199174 100644 --- a/R/col_vals_lt.R +++ b/R/col_vals_lt.R @@ -366,17 +366,12 @@ col_vals_lt <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = value, - assertion_type = "col_vals_lt" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = value, + assertion_type = "col_vals_lt" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -413,7 +408,7 @@ col_vals_lt <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_lte.R b/R/col_vals_lte.R index c99ec088a..6b912defe 100644 --- a/R/col_vals_lte.R +++ b/R/col_vals_lte.R @@ -367,17 +367,12 @@ col_vals_lte <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = value, - assertion_type = "col_vals_lte" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = value, + assertion_type = "col_vals_lte" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -414,7 +409,7 @@ col_vals_lte <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_make_set.R b/R/col_vals_make_set.R index 76700243d..3eb946bc8 100644 --- a/R/col_vals_make_set.R +++ b/R/col_vals_make_set.R @@ -359,17 +359,12 @@ col_vals_make_set <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = set, - assertion_type = "col_vals_make_set" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = set, + assertion_type = "col_vals_make_set" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -405,7 +400,7 @@ col_vals_make_set <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_make_subset.R b/R/col_vals_make_subset.R index a5b34c455..7e2763169 100644 --- a/R/col_vals_make_subset.R +++ b/R/col_vals_make_subset.R @@ -356,17 +356,12 @@ col_vals_make_subset <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = set, - assertion_type = "col_vals_make_subset" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = set, + assertion_type = "col_vals_make_subset" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -402,7 +397,7 @@ col_vals_make_subset <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_not_between.R b/R/col_vals_not_between.R index a21f2749c..4252f671e 100644 --- a/R/col_vals_not_between.R +++ b/R/col_vals_not_between.R @@ -432,22 +432,16 @@ col_vals_not_between <- function( agent <- x # Avoid rlang (>= 0.3.0) soft deprecation warning - # Quosure lists can't be concatenated with objects other than quosures - + # Quosure lists can't be concatenated with objects other than quosures. left <- as.list(left) right <- as.list(right) - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = c(left, right), - assertion_type = "col_vals_not_between" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = c(left, right), + assertion_type = "col_vals_not_between" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -484,7 +478,7 @@ col_vals_not_between <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_not_equal.R b/R/col_vals_not_equal.R index a9062d14f..b911c7072 100644 --- a/R/col_vals_not_equal.R +++ b/R/col_vals_not_equal.R @@ -364,17 +364,12 @@ col_vals_not_equal <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = value, - assertion_type = "col_vals_not_equal" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = value, + assertion_type = "col_vals_not_equal" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -411,7 +406,7 @@ col_vals_not_equal <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_not_in_set.R b/R/col_vals_not_in_set.R index f40c93deb..6322d79c9 100644 --- a/R/col_vals_not_in_set.R +++ b/R/col_vals_not_in_set.R @@ -353,17 +353,12 @@ col_vals_not_in_set <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = set, - assertion_type = "col_vals_not_in_set" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = set, + assertion_type = "col_vals_not_in_set" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -399,7 +394,7 @@ col_vals_not_in_set <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_not_null.R b/R/col_vals_not_null.R index 175d6f326..e173d3144 100644 --- a/R/col_vals_not_null.R +++ b/R/col_vals_not_null.R @@ -343,17 +343,12 @@ col_vals_not_null <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = values, - assertion_type = "col_vals_not_null" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = values, + assertion_type = "col_vals_not_null" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -388,7 +383,7 @@ col_vals_not_null <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_null.R b/R/col_vals_null.R index 11bc5938f..3b760d13e 100644 --- a/R/col_vals_null.R +++ b/R/col_vals_null.R @@ -342,17 +342,12 @@ col_vals_null <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = values, - assertion_type = "col_vals_null" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = values, + assertion_type = "col_vals_null" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -387,7 +382,7 @@ col_vals_null <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_regex.R b/R/col_vals_regex.R index 3f6a6bbf7..6b5ff4148 100644 --- a/R/col_vals_regex.R +++ b/R/col_vals_regex.R @@ -358,17 +358,12 @@ col_vals_regex <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = regex, - assertion_type = "col_vals_regex" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = regex, + assertion_type = "col_vals_regex" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -405,7 +400,7 @@ col_vals_regex <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/col_vals_within_spec.R b/R/col_vals_within_spec.R index 945ba4e1c..e9061a64e 100644 --- a/R/col_vals_within_spec.R +++ b/R/col_vals_within_spec.R @@ -423,17 +423,12 @@ col_vals_within_spec <- function( agent <- x - if (is.null(brief)) { - - brief <- - generate_autobriefs( - agent = agent, - columns = columns, - preconditions = preconditions, - values = spec, - assertion_type = "col_vals_within_spec" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, values = spec, + assertion_type = "col_vals_within_spec" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns, agent) @@ -470,7 +465,7 @@ col_vals_within_spec <- function( actions = covert_actions(actions, agent), step_id = step_id[i], label = label[[i, j]], - brief = brief[i], + brief = brief[[i, j]], active = active ) } diff --git a/R/conjointly.R b/R/conjointly.R index b6c44f39d..ff398d741 100644 --- a/R/conjointly.R +++ b/R/conjointly.R @@ -401,16 +401,12 @@ conjointly <- function( agent <- x - if (is.null(brief)) { - - brief <- - create_autobrief( - agent = agent, - assertion_type = "conjointly", - preconditions = preconditions, - values = validation_formulas - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + segments_list = segments_list, + preconditions = preconditions, values = validation_formulas, + assertion_type = "conjointly" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns = "column", agent) @@ -446,7 +442,7 @@ conjointly <- function( actions = covert_actions(actions, agent), step_id = step_id, label = label[[i]], - brief = brief, + brief = brief[[i]], active = active ) } diff --git a/R/row_count_match.R b/R/row_count_match.R index 8e3dc5156..ee55cec1a 100644 --- a/R/row_count_match.R +++ b/R/row_count_match.R @@ -362,15 +362,12 @@ row_count_match <- function( agent <- x - if (is.null(brief)) { - - brief <- - create_autobrief( - agent = agent, - assertion_type = "row_count_match", - values = count - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + segments_list = segments_list, + preconditions = preconditions, values = count, + assertion_type = "row_count_match" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns = "column", agent) @@ -405,7 +402,7 @@ row_count_match <- function( actions = covert_actions(actions, agent), step_id = step_id, label = label[[i]], - brief = brief, + brief = brief[[i]], active = active ) } diff --git a/R/rows_complete.R b/R/rows_complete.R index f081b37f5..de3ba6b85 100644 --- a/R/rows_complete.R +++ b/R/rows_complete.R @@ -333,15 +333,12 @@ rows_complete <- function( columns <- paste(columns, collapse = ", ") } - if (is.null(brief)) { - - brief <- - create_autobrief( - agent = agent, - assertion_type = "rows_complete", - column = columns - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, + assertion_type = "rows_complete" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns = "column", agent) @@ -376,7 +373,7 @@ rows_complete <- function( actions = covert_actions(actions, agent), step_id = step_id, label = label[[i]], - brief = brief, + brief = brief[[i]], active = active ) } diff --git a/R/rows_distinct.R b/R/rows_distinct.R index 9298078f4..267e28dd4 100644 --- a/R/rows_distinct.R +++ b/R/rows_distinct.R @@ -334,15 +334,12 @@ rows_distinct <- function( columns <- paste(columns, collapse = ", ") } - if (is.null(brief)) { - - brief <- - create_autobrief( - agent = agent, - assertion_type = "rows_distinct", - column = columns - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + columns = columns, segments_list = segments_list, + preconditions = preconditions, + assertion_type = "rows_distinct" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns = "column", agent) @@ -377,7 +374,7 @@ rows_distinct <- function( actions = covert_actions(actions, agent), step_id = step_id, label = label[[i]], - brief = brief, + brief = brief[[i]], active = active ) } diff --git a/R/serially.R b/R/serially.R index b432e4858..8ba63a524 100644 --- a/R/serially.R +++ b/R/serially.R @@ -682,7 +682,7 @@ serially <- function( actions = covert_actions(actions, agent), step_id = step_id, label = label[[i]], - brief = brief, + brief = brief[[i]], active = active ) } diff --git a/R/specially.R b/R/specially.R index 368ede097..691cc5532 100644 --- a/R/specially.R +++ b/R/specially.R @@ -356,14 +356,12 @@ specially <- function( agent <- x - if (is.null(brief)) { - - brief <- - create_autobrief( - agent = agent, - assertion_type = "specially" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + segments_list = segments_list, + preconditions = preconditions, + assertion_type = "specially" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns = "column", agent) @@ -399,7 +397,7 @@ specially <- function( actions = covert_actions(actions, agent), step_id = step_id, label = label[[i]], - brief = brief, + brief = brief[[i]], active = active ) } diff --git a/R/tbl_match.R b/R/tbl_match.R index 7360d9291..b1249c475 100644 --- a/R/tbl_match.R +++ b/R/tbl_match.R @@ -334,14 +334,12 @@ tbl_match <- function( agent <- x - if (is.null(brief)) { - - brief <- - create_autobrief( - agent = agent, - assertion_type = "tbl_match" - ) - } + brief <- resolve_brief( + brief = brief, agent = agent, + segments_list = segments_list, + preconditions = preconditions, + assertion_type = "tbl_match" + ) # Normalize any provided `step_id` value(s) step_id <- normalize_step_id(step_id, columns = "column", agent) @@ -374,8 +372,8 @@ tbl_match <- function( seg_val = seg_val, actions = covert_actions(actions, agent), step_id = step_id, - label = label, - brief = brief, + label = label[[i]], + brief = brief[[i]], active = active ) } diff --git a/R/utils.R b/R/utils.R index 2c87a1dbf..dae88b117 100644 --- a/R/utils.R +++ b/R/utils.R @@ -238,7 +238,43 @@ is_secret_agent <- function(x) { is_ptblank_agent(x) && (x$label == "::QUIET::") } -resolve_label <- function(label, columns = "", segments = "") { +resolve_brief <- function(brief, agent, + columns = list(NULL), segments_list = list(NULL), + preconditions = NULL, values = NULL, + assertion_type) { + + n_columns <- length(columns) + n_segments <- length(segments_list) + n_combinations <- n_columns * n_segments + + # If missing, apply auto-brief + if (is.null(brief)) { + brief <- generate_autobriefs( + agent = agent, columns = columns, + preconditions = preconditions, values = values, + assertion_type = assertion_type + ) + # auto-brief is generated once per column - need to recycle by segment + brief <- rep(brief, each = n_segments) + } + + # Brief must be a single string or matched in length + if (!length(brief) %in% c(1L, n_combinations)) { + cli::cli_abort(paste0( + "`brief` must be length 1", + if (n_combinations != 1L) " or {n_combinations}", + ", not {length(brief)}." + )) + } + + # Recycle the string + brief <- rep_len(brief, n_combinations) + # Return packed vector/matrix for iteration over steps + pack_by_col_seg(brief, n_columns, n_segments, c(columns, segments)) + +} + +resolve_label <- function(label, columns = list(NULL), segments = list(NULL)) { n_columns <- length(columns) n_segments <- length(segments) n_combinations <- n_columns * n_segments @@ -246,23 +282,29 @@ resolve_label <- function(label, columns = "", segments = "") { if (is.null(label)) { label <- NA_character_ } - # If length-1, match length of col-x-seg combination - if (length(label) == 1) { - label <- rep_len(label, n_combinations) + # Label must be a single string or matched in length + if (!length(label) %in% c(1L, n_combinations)) { + cli::cli_abort(paste0( + "`label` must be length 1", + if (n_combinations != 1L) " or {n_combinations}", + ", not {length(label)}." + )) } - # Check for length match - if (length(label) != n_combinations) { - rlang::abort(paste0("`label` must be length 1 or ", n_combinations, - ", not ", length(label))) - } - # Create a columns * segments matrix of the (recycled) label vector - # - Fill by row to preserve order (for loops iterate the j before the i) - out <- matrix(label, nrow = n_columns, ncol = n_segments, byrow = TRUE) + # Recycle the string + label <- rep_len(label, n_combinations) + # Return packed vector/matrix for iteration over steps + pack_by_col_seg(label, n_columns, n_segments, c(columns, segments)) +} + +# Create a columns * segments matrix/vector for an input (ex: `brief`, `label`) +# - Subsettable via `out[col]`, `out[seg]`, or `out[col,seg]` +pack_by_col_seg <- function(x, n_columns, n_segments, packed_dim) { + # Fill by row to preserve order (for loops iterate the j before the i) + out <- matrix(x, nrow = n_columns, ncol = n_segments, byrow = TRUE) # If missing columns and/or segments, collapse to vector/scalar - if (missing(columns) || missing(segments)) { + if (any(lengths(packed_dim) == 0)) { out <- as.vector(out) } - # A matrix/vector subsettable via `out[col]`, `out[seg]`, or `out[col,seg]` out } diff --git a/tests/testthat/test-brief.R b/tests/testthat/test-brief.R new file mode 100644 index 000000000..f422b9bcf --- /dev/null +++ b/tests/testthat/test-brief.R @@ -0,0 +1,229 @@ +test_that("`brief` recycles when possible", { + + agent <- create_agent(small_table) + get_briefs <- function(x) x$validation_set$brief + + expect_length( + agent %>% + col_exists(c("a", "b"), brief = NULL) %>% + get_briefs(), + 2L + ) + + expect_identical( + agent %>% + col_exists(c("a", "b"), brief = NA) %>% + get_briefs(), + c(NA_character_, NA_character_) + ) + + expect_identical( + agent %>% + col_exists(c("a", "b"), brief = c("x", NA)) %>% + get_briefs(), + c("x", NA_character_) + ) + + expect_equal( + agent %>% + col_exists(c("a", "b"), brief = "one") %>% + get_briefs(), + c("one", "one") + ) + + expect_equal( + agent %>% + col_exists(c("a", "b"), brief = c("one", "two")) %>% + get_briefs(), + c("one", "two") + ) + + expect_error( + agent %>% + col_vals_equal( + c("a", "b"), 0, + segments = vars(f), + brief = c("one", "two", "three") + ), + "must be length 1 or 6, not 3" + ) + + expect_error( + agent %>% + col_exists("a", brief = c("one", "two")), + "must be length 1, not 2" + ) + +}) + +test_that("Briefs batch tests", { + + validation_fns <- all_validations_fns_vec() + validation_fns <- setdiff(validation_fns, c("serially", "conjointly", "specially")) + validation_fns <- mget(validation_fns, asNamespace("pointblank")) + validation_fn_args <- sapply(validation_fns, function(x) { + paste(intersect(names(formals(x)), c("segments", "columns")), collapse = "+") + }) + validation_fn_args <- validation_fn_args[validation_fn_args != ""] + validation_fn_args[grepl(x = names(validation_fn_args), "^rows_")] <- "rows_*" + table(validation_fn_args) + + agent <- create_agent(small_table) + test_multi_briefs <- function(f, ...) { + test <- validation_fn_args[[f]] + f <- validation_fns[[f]] + cols <- c("a", "b") + segs <- c("high", "low", "mid") + switch(test, + "columns" = { + out <- cols + agent <- agent %>% + f(columns = c("a", "b"), ..., brief = cols) # 2-steps + }, + "segments" = { + out <- segs + agent <- agent %>% + f(segments = vars(f), ..., brief = segs) # 3-steps + }, "columns+segments" = { + out <- as.vector(outer(segs, cols, function(s, c) paste0(c, ":", s))) + agent <- agent %>% + f(columns = c("a", "b"), segments = vars(f), ..., brief = out) # 6-steps + }, "rows_*" = { + out <- segs + agent <- agent %>% + f(columns = c("a", "b"), segments = vars(f), ..., brief = segs) # 3-steps + } + ) + if (rlang::is_interactive()) print(agent) + expect_identical(out, agent$validation_set$brief) + } + + # columns + test_multi_briefs("col_is_character") + test_multi_briefs("col_is_numeric") + test_multi_briefs("col_is_integer") + test_multi_briefs("col_is_logical") + test_multi_briefs("col_is_date") + test_multi_briefs("col_is_posix") + test_multi_briefs("col_is_factor") + test_multi_briefs("col_exists") + + # columns + segments + test_multi_briefs("col_vals_lt", value = 5) + test_multi_briefs("col_vals_lte", value = 5) + test_multi_briefs("col_vals_equal", value = 5) + test_multi_briefs("col_vals_not_equal", value = 5) + test_multi_briefs("col_vals_gte", value = 5) + test_multi_briefs("col_vals_gt", value = 5) + test_multi_briefs("col_vals_between", left = 2, right = 5) + test_multi_briefs("col_vals_not_between", left = 2, right = 5) + test_multi_briefs("col_vals_in_set", set = c(2, 5)) + test_multi_briefs("col_vals_not_in_set", set = c(2, 5)) + test_multi_briefs("col_vals_make_set", set = c(2, 5)) + test_multi_briefs("col_vals_make_subset", set = c(2, 5)) + test_multi_briefs("col_vals_null") + test_multi_briefs("col_vals_not_null") + test_multi_briefs("col_vals_increasing") + test_multi_briefs("col_vals_decreasing") + test_multi_briefs("col_vals_regex", regex = "abc") + test_multi_briefs("col_vals_within_spec", spec = "email") + + # segments + test_multi_briefs("col_vals_expr", expr = expr(a %% 1 == 0)) + test_multi_briefs("row_count_match", count = small_table) + test_multi_briefs("tbl_match", tbl_compare = small_table) + + # rows_* + test_multi_briefs("rows_distinct") + test_multi_briefs("rows_complete") + +}) + +test_that("Briefs batch tests: special validations", { + + agent <- create_agent(small_table) + get_briefs <- function(x) x$validation_set$brief + + # Special: serially + expect_identical( + agent %>% + serially( + ~ test_col_vals_lt(., columns = a, value = 8), + ~ test_col_vals_gt(., columns = c, value = vars(a)), + ~ col_vals_not_null(., columns = b), + preconditions = ~ . %>% dplyr::filter(a < 10), + actions = action_levels(warn_at = 0.1, stop_at = 0.2), + label = "The `serially()` step.", + active = FALSE, + brief = "custom brief" + ) %>% + get_briefs() + , + "custom brief" + ) + + # Special: specially + expect_identical( + agent %>% + specially( + fn = function(x) { ... }, + preconditions = ~ . %>% dplyr::filter(a < 10), + actions = action_levels(warn_at = 0.1, stop_at = 0.2), + label = "The `specially()` step.", + active = FALSE, + brief = "custom brief" + ) %>% + get_briefs() + , + "custom brief" + ) + + # Special: conjointly (no segments) + expect_identical( + agent %>% + conjointly( + ~ col_vals_lt(., columns = a, value = 8), + ~ col_vals_gt(., columns = c, value = vars(a)), + ~ col_vals_not_null(., columns = b), + preconditions = ~ . %>% dplyr::filter(a < 10), + # segments = b ~ c("group_1", "group_2"), + actions = action_levels(warn_at = 0.1, stop_at = 0.2), + label = "The `conjointly()` step.", + active = FALSE, + brief = "custom brief" + ) %>% + get_briefs(), + "custom brief" + ) + + # Special: conjointly (expanded with segments) + expect_identical( + agent %>% + conjointly( + ~ col_vals_lt(., columns = a, value = 8), + ~ col_vals_gt(., columns = c, value = vars(a)), + ~ col_vals_not_null(., columns = b), + preconditions = ~ . %>% dplyr::filter(a < 10), + segments = b ~ c("group_1", "group_2"), + actions = action_levels(warn_at = 0.1, stop_at = 0.2), + label = "The `conjointly()` step.", + active = FALSE, + brief = "custom brief constant" + ) %>% + conjointly( + ~ col_vals_lt(., columns = a, value = 8), + ~ col_vals_gt(., columns = c, value = vars(a)), + ~ col_vals_not_null(., columns = b), + preconditions = ~ . %>% dplyr::filter(a < 10), + segments = b ~ c("group_1", "group_2"), + actions = action_levels(warn_at = 0.1, stop_at = 0.2), + label = "The `conjointly()` step.", + active = FALSE, + brief = c("custom brief multi1", "custom brief multi2") + ) %>% + get_briefs(), + c("custom brief constant", "custom brief constant", + "custom brief multi1", "custom brief multi2") + ) + +})