scope_tidy: Scoping a tidy tibble allowing to tidy select

View source: R/scope_tidy.R

scope_tidyR Documentation

Scoping a tidy tibble allowing to tidy select

Description

This function uses the information from a model tidy tibble to generate a data frame exposing the different variables of the model, data frame that could be used for tidy selection. In addition, columns "var_type", "var_class" and "contrasts_type" are scoped and their values are added as attributes to the data frame. For example, if var_type='continuous' for variable "age", then the attribute attr(.$age, 'gtsummary.var_type') <- 'continuous' is set. That attribute is then used in a selector like all_continuous(). Note: attributes are prefixed with "gtsummary." to be compatible with selectors provided by {gtsummary}.

Usage

scope_tidy(x, data = NULL)

Arguments

x

(data.frame)
A tidy tibble, with a "variable" column, as returned by tidy_identify_variables().

data

(data.frame)
An optional data frame the attributes will be added to.

Value

A data frame.

Examples

mod <- lm(Sepal.Length ~ Sepal.Width * Species, data = iris)
tt <- mod |> tidy_and_attach() |> tidy_add_contrasts()

scope_tidy(tt) |> str()
scope_tidy(tt, data = model_get_model_frame(mod)) |> str()

scope_tidy(tt) |> dplyr::select(dplyr::starts_with("Se")) |> names()
scope_tidy(tt) |> dplyr::select(where(is.factor)) |> names()
scope_tidy(tt) |> dplyr::select(all_continuous()) |> names()
scope_tidy(tt) |> dplyr::select(all_contrasts()) |> names()
scope_tidy(tt) |> dplyr::select(all_interaction()) |> names()
scope_tidy(tt) |> dplyr::select(all_intercepts()) |> names()

larmarange/broom.helpers documentation built on Sept. 27, 2024, 12:35 a.m.