Решение 1: быстрое и (не очень) грязное
df <- tidyr::tribble(
~A, ~B, ~C,
1, 2, 3,
NA, 2, 3,
1, 2, NA
)
# Checks each column, but is a pain to maintain
testthat::test_that("Variable specific checks", {
res <- apply(df, 2, function(x) sum(is.na(x))>0)
testthat::expect_true(all(res), label = paste(paste(which(res), collapse=", "), "contain(s) NA(s)"))
})
, которое должно вернуть
Error: Test failed: 'Variable specific checks'
* 1, 3 contain(s) NA isn't true.
Решение 2: адаптировать функцию wait_ () к вашим потребностям
expect_true2 <- function(object, info = NULL, label = NULL) {
act <- testthat::quasi_label(rlang::enquo(object), label, arg = "object")
testthat::expect(identical(as.vector(act$val), TRUE), sprintf("Column %s contain(s) NA(s).",
act$lab), info = info)
invisible(act$val)
}
testthat::test_that("Variable specific checks", {
res <- apply(df, 2, function(x) sum(is.na(x))>0)
expect_true2(all(res), label = paste(which(res), collapse=","))
})
, который должен вернуть
Error: Test failed: 'Variable specific checks'
* Column 1,3 contain(s) NA(s).