Skip to content

Commit

Permalink
resolve_briefs() wraps generate_autobriefs()
Browse files Browse the repository at this point in the history
  • Loading branch information
yjunechoe committed Sep 8, 2024
1 parent 27bf33f commit 6571553
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
12 changes: 6 additions & 6 deletions R/col_exists.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ col_exists <- function(

agent <- x

if (is.null(brief)) {
brief <-
generate_autobriefs(agent, columns, preconditions, values, "col_exists")
} else {
brief <- resolve_briefs(brief, columns)
}
brief <- resolve_briefs(
brief = brief, agent = agent,
columns = columns,
preconditions = preconditions,
assertion_type = "col_exists"
)

# Normalize any provided `step_id` value(s)
step_id <- normalize_step_id(step_id, columns, agent)
Expand Down
18 changes: 6 additions & 12 deletions R/col_vals_equal.R
Original file line number Diff line number Diff line change
Expand Up @@ -365,18 +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"
)
} else {
brief <- resolve_briefs(brief, columns, segments_list)
}
brief <- resolve_briefs(
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)
Expand Down
29 changes: 17 additions & 12 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,24 @@ is_secret_agent <- function(x) {
is_ptblank_agent(x) && (x$label == "::QUIET::")
}

resolve_briefs <- function(brief, columns = "", segments = "") {
n_columns <- length(columns)
n_segments <- length(segments)
n_combinations <- n_columns * n_segments
# Brief must be a single string or matched in length
if (!length(brief) %in% c(1L, n_combinations)) {
rlang::abort(paste0(
"`brief` must be length 1 or ", n_combinations,
", not ", length(brief)
))
resolve_briefs <- function(brief, agent,
columns = "", segments_list = "",
preconditions, values, assertion_type) {
if (is.null(brief)) {
generate_autobriefs(agent, columns, preconditions, values, assertion_type)
} else {
n_columns <- length(columns)
n_segments <- length(segments_list)
n_combinations <- n_columns * n_segments
# Brief must be a single string or matched in length
if (!length(brief) %in% c(1L, n_combinations)) {
cli::cli_abort(
"`brief` must be length 1 or {n_combinations}, not {length(brief)}."
)
}
# Recycle the string
rep_len(brief, n_combinations)
}
# Recycle the string
rep_len(brief, n_combinations)
}

resolve_label <- function(label, columns = "", segments = "") {
Expand Down

0 comments on commit 6571553

Please sign in to comment.