
Cheaply check whether .data is conformable with an xmap_tbl
Source: R/apply_xmap.r
validate_apply_xmap.Rdvalidate_apply_xmap() checks the same two conditions apply_xmap()
requires before transforming .data – every keys_from key has a
matching .xmap$.from link, and no values_from column has a missing
value – and returns a single logical, without building the
offending-rows/columns detail objects that diagnose_apply_xmap() does.
It's the primitive to reach for when you only need a pass/fail answer –
e.g. checking many .data/.xmap group pairs with dplyr::mutate() or
purrr::map2_lgl() before applying any of them. Reach for
diagnose_apply_xmap() once validate_apply_xmap() says something
failed and you need to know why; apply_xmap() checks the same
conditions at transform time and aborts with a message pointing at the
offending condition.
Usage
validate_apply_xmap(
.data,
.xmap,
values_from,
keys_from = names(.xmap$.from),
...
)Examples
abc_xmap <- demo$abc_links |>
as_xmap_tbl(from = "lower", to = "upper", weight_by = "share")
abc_data <- tibble::tibble(
lower = unique(demo$abc_links$lower),
count = runif(length(unique(demo$abc_links$lower)), min = 100, max = 500)
)
validate_apply_xmap(abc_data, abc_xmap, values_from = count)
#> [1] TRUE