Returns one cell of a spicy table as a character scalar, formatted exactly as the table displays it – same decimals, same p style, same interval punctuation, same journal style. Designed for inline R chunks in Quarto / R Markdown:
Arguments
- x
A table returned by
table_regression(),table_categorical(),table_continuous(),table_continuous_lm(),table_outcome(),table_categorical_svy()ortable_continuous_svy()(default output) – every familyas_structured()accepts.- variable
The source variable, unquoted or as a string; or a fit-statistic token (
"n","r2", ...).- level
For a factor variable, the level, as a string.
"(Missing)"addresses the missing-value category by role. Ontable_continuous_lm(), whose groups are columns rather than rows, it names the group.- column
A column token, or a
{token}pattern.NULL(the default) returns the estimate-like column of the row when it is unambiguous: the family's primary estimate. That is the coefficient fortable_regression()– always token"b": an exponentiated table changes its header to OR, IRR or HR, never its token – the contrast ("delta") or, across a numericby, the slope ("b") fortable_continuous_lm(), the mean ("m") or, on a median-only table, the median ("med","med_iqr") fortable_continuous(), and the count ("n") fortable_categorical(). A row carrying none of them refuses and lists its tokens.- model
In a multi-model table, the model: its label (as displayed in the column spanners) or its position.
Addressing
The row is found by identity, not by display text: variable
names the source column (.variable in the typed body), level
the level (.level). Custom labels, a style, or a translated
display never change the call. As a convenience, a variable
that matches no source column is looked up among the displayed
labels before erroring. The missing-value category is addressed by
level = "(Missing)" whatever its displayed (possibly deduplicated)
label, through its row role. Fit statistics are addressed by their
token as variable (inline(tbl, "n"), inline(tbl, "r2")).
A statistic that belongs to a whole variable rather than to one of
its levels sits on the variable's own row: the p of a
table_categorical() block, its association measure, its SMD. Leave
level out to cite it (inline(tbl, smoking, column = "p")).
table_continuous_lm() lays its groups out sideways – one row per
outcome, the by levels as columns (M (Female), M (Male)) –
so there level names the group whose column you want:
inline(tbl, bmi, "Female", "emmean"). The columns that belong to
no group (the contrast, its interval, p, n) are cited without
one, as before.
The column is a token of the typed contract ("b", "se",
"p", "ci", "or", "ame", "n", "pct", "m", ... – see
as_structured()'s col_meta), never a display header. "ci"
composes the interval with the style's brackets and separator, and
so does every other interval token the table carries ("med_ci",
"ame_ci", "assoc_ci"): each addresses its own bounds. In
a multi-model table, model selects the model by its spanner
label or position; in a by table, the spanners are the groups,
so model selects the group the same way.
Patterns
A column containing { is a pattern: each {token} is replaced
by the corresponding cell, so one call quotes a full sentence
fragment:
{ci_label} inserts the interval label of the interval the pattern
cites (95% CI, or Med 95% CI in a pattern quoting {med_ci}) –
the first one when it cites several, the table's first when it cites
none. Note that {p} carries the floor operator when the table does
(<.001), so write p {p} rather than p = {p} in patterns that
may hit the floor.
Errors
Every misaddressing is a classed error that lists the available choices: unknown variables list the variables, missing levels list the levels, unknown tokens list the table's tokens, ambiguous models list the spanner labels. A cell the table itself displays as undefined (an aliased coefficient's en-dash) refuses with the reason rather than pasting a dash into a sentence.
See also
as_structured() for the typed contract behind the
addressing.
Examples
fit <- lm(wellbeing_score ~ age + sex, data = sochealth)
tbl <- table_regression(fit)
inline(tbl, age, column = "b")
#> [1] "0.04"
inline(tbl, sex, "Male", "{b} ({ci_label} {ci}; p {p})")
#> [1] "3.90 (95% CI [2.14, 5.65]; p <.001)"
inline(tbl, "n")
#> [1] "1200"