Class predicates returning a single logical indicating whether
x inherits from the corresponding tabular S7 class. Use them
to gate user-side code that branches on what a verb has
returned, to write defensive helpers that wrap tabular pipelines,
or to assert intermediate shapes during pipeline debugging.
Usage
is_tabular_spec(x)
is_tabular_grid(x)
is_col_spec(x)
is_header_node(x)
is_sort_spec(x)
is_style_node(x)
is_style_layer(x)
is_style_spec(x)
is_pagination_spec(x)
is_preset_spec(x)
is_subgroup_spec(x)
is_inline_ast(x)Value
A single TRUE / FALSE. Use in if / stopifnot
guards, or chain into validation helpers.
A length-1 logical — TRUE or FALSE. Never NA.
Details
Twelve predicates cover the full S7 surface:
| predicate | tests for | produced by |
is_tabular_spec() | tabular_spec | tabular() and every build verb |
is_tabular_grid() | tabular_grid | as_grid() |
is_col_spec() | col_spec | col_spec() |
is_header_node() | header_node | headers() (internal nodes) |
is_sort_spec() | sort_spec | sort_rows() |
is_style_node() | style_node | style() (per-cell style) |
is_style_layer() | style_layer | style() (one per call) |
is_style_spec() | style_spec | style() (the cascade root) |
is_pagination_spec() | pagination_spec | paginate() |
is_preset_spec() | preset_spec | preset(), set_preset() |
is_subgroup_spec() | subgroup_spec | subgroup() |
is_inline_ast() | inline_ast | parse_inline() (post-format) |
Predicates never error — they return FALSE for NULL, vectors,
objects of any other class, and S7 objects from other packages.
Use them at any layer of a user's pipeline without a defensive
tryCatch().
See also
Class definitions: tabular_classes.
Verbs producing each class: tabular(), col_spec(),
headers(), sort_rows(), style(), paginate(),
preset(), as_grid().
Examples
# ---- Example 1: Gate user-side code on the spec class ----
#
# A user-side helper that pre-validates its input before piping
# into a downstream tabular chain. The predicate returns FALSE
# for any non-spec input without raising, so the helper can emit
# a friendlier error than tabular's own S7 validator would.
add_safety_footnote <- function(spec) {
if (!is_tabular_spec(spec)) {
stop("`spec` must be a tabular_spec; build one with tabular().")
}
spec
}
demo <- tabular(cdisc_saf_demo, titles = "Demographics")
is_tabular_spec(demo) # TRUE
#> [1] TRUE
is_tabular_spec("not a spec") # FALSE — does not raise
#> [1] FALSE
add_safety_footnote(demo)
Demographics
variable stat_label placebo drug_50 drug_100 Total Age (years) n 86 96 72 254 Age (years) Mean (SD) 75.2 (8.59) 76.0 (8.11) 73.8 (7.94) 75.1 (8.25) Age (years) Median 76.0 78.0 75.5 77.0 Age (years) Q1, Q3 69.2, 81.8 71.0, 82.0 70.5, 79.0 70.0, 81.0 Age (years) Min, Max 52, 89 51, 88 56, 88 51, 89 Sex, n (%) F 53 (61.6) 55 (57.3) 35 (48.6) 143 (56.3) Sex, n (%) M 33 (38.4) 41 (42.7) 37 (51.4) 111 (43.7) Race, n (%) WHITE 78 (90.7) 90 (93.8) 62 (86.1) 230 (90.6) Race, n (%) BLACK OR AFRICAN AMERICAN 8 (9.3) 6 (6.2) 9 (12.5) 23 (9.1) Race, n (%) ASIAN 0 (0.0) 0 (0.0) 0 (0.0) 0 (0.0) Race, n (%) AMERICAN INDIAN OR ALASKA NATIVE 0 (0.0) 0 (0.0) 1 (1.4) 1 (0.4)
# ---- Example 2: Assert intermediate shapes during debugging ----
#
# When chaining many verbs, dropping `stopifnot()` between verbs
# gives a clear stack trace if a verb silently returns the wrong
# type. Predicates are cheap (single S7 dispatch each) and never
# error, so they are safe to leave in pipelines during dev.
n <- stats::setNames(cdisc_saf_n$n, cdisc_saf_n$arm_short)
spec <- tabular(
cdisc_saf_demo,
titles = c("Table 14.1.1", "Demographics",
"Safety Population")
) |>
cols(
variable = col_spec(usage = "group", label = "Characteristic"),
stat_label = col_spec(label = "Statistic"),
placebo = col_spec(label = "Placebo\nN={n['placebo']}", align = "decimal"),
drug_50 = col_spec(label = "Drug 50\nN={n['drug_50']}", align = "decimal"),
drug_100 = col_spec(label = "Drug 100\nN={n['drug_100']}", align = "decimal"),
Total = col_spec(label = "Total\nN={n['Total']}", align = "decimal")
) |>
sort_rows(by = c("variable", "stat_label"))
stopifnot(
is_tabular_spec(spec),
is_col_spec(spec@cols[["placebo"]]),
is_sort_spec(spec@sort)
)
grid <- as_grid(spec)
stopifnot(is_tabular_grid(grid))