Skip to content

Commit

Permalink
Merge pull request #554 from yjunechoe/drop-tbl_checked
Browse files Browse the repository at this point in the history
Option to drop `tbl_checked` information
  • Loading branch information
rich-iannone authored Aug 6, 2024
2 parents 856a7f4 + 8f027fc commit 82ee45e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions R/get_sundered_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ get_sundered_data <- function(
)
}

# Stop function if `tbl_checked` is not present
if (!"tbl_checked" %in% colnames(agent$validation_set)) {
stop(
"`agent` is missing `tbl_checked` information required for sundering. ",
"See `?interrogate`."
)
}

# Get the row count of the input table
row_count_input_tbl <-
input_tbl %>%
Expand Down
15 changes: 15 additions & 0 deletions R/interrogate.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
#' The default is `TRUE` and further options allow for fine control of how
#' these rows are collected.
#'
#' @param extract_tbl_checked *Collect validation results from each step*
#'
#' `scalar<logical>` // *default:* `TRUE`
#'
#' An option to collect processed data frames produced by executing the
#' validation steps. This information is necessary for some functions
#' (e.g., `get_sundered_data()`), but may grow to a large size. To opt out
#' of attaching this data to the agent, set this argument to `FALSE`.
#'
#' @param get_first_n *Get the first n values*
#'
#' `scalar<integer>` // *default:* `NULL` (`optional`)
Expand Down Expand Up @@ -143,6 +152,7 @@
interrogate <- function(
agent,
extract_failed = TRUE,
extract_tbl_checked = TRUE,
get_first_n = NULL,
sample_n = NULL,
sample_frac = NULL,
Expand Down Expand Up @@ -729,6 +739,11 @@ interrogate <- function(
# all validation steps have been carried out
class(agent) <- c("has_intel", "ptblank_agent")

# Drop $tbl_checked if `extract_tbl_checked = FALSE`
if (!extract_tbl_checked) {
agent$validation_set$tbl_checked <- NULL
}

# Add the ending time to the `agent` object
agent$time_end <- Sys.time()

Expand Down
10 changes: 10 additions & 0 deletions man/interrogate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/testthat/test-sundering.R
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,23 @@ test_that("an error occurs if using `get_sundered_data()` when agent has no inte
get_sundered_data()
)
})

test_that("an error occurs if using `get_sundered_data()` when agent is missing `$tbl_checked`", {

# Expect an error if the agent performed an interrogation
# with `extract_tbl_checked = FALSE`
expect_error(
create_agent(tbl = small_table) %>%
col_vals_gt(vars(date_time), vars(date), na_pass = TRUE) %>%
col_vals_gt(vars(b), vars(g), na_pass = TRUE) %>%
rows_distinct(vars(d, e)) %>%
rows_distinct(vars(a, f)) %>%
col_vals_gt(vars(d), 100) %>%
col_vals_equal(vars(d), vars(d), na_pass = TRUE) %>%
col_vals_between(vars(c), left = vars(a), right = vars(d), na_pass = TRUE) %>%
interrogate(extract_tbl_checked = FALSE) %>%
get_sundered_data(),
"missing `tbl_checked`"
)
})

0 comments on commit 82ee45e

Please sign in to comment.