Skip to contents

A convenience wrapper for adding one or more new variables to an existing dictionary. Each variable's name is taken from its corresponding named argument in ..., so there is no need to pass name inside the variable constructor itself.

Usage

bind_variables(dictionary, ..., .list = NULL)

Arguments

dictionary

A data dictionary object

...

Named arguments. Each name becomes the variable name, and each value is a call to a variable constructor such as nominal_variable(), numeric_variable(), logical_variable(), identifier_variable(), or date_variable(). The name argument of the constructor may be omitted; bind_variables will inject it automatically.

.list

This argument allows bind_variables to be used programmatically and is optional. It is intended to be used as an alternative to ..... A named list of DataVariable objects. Each element's list-entry name will be used to set (or override) the variable name.

Value

A data dictionary object

Details

bind_variables does not allow overwriting variables already present in dictionary. To modify existing variables use the set_* family (e.g. set_labels(), set_units()).

Examples


meta <- as_data_dictionary(iris)

meta <- meta |>
  bind_variables(
    train_test = nominal_variable(
      label = "Train/test split",
      category_levels = c("train", "test"),
      category_labels = c("Training data", "Testing data")
    )
  )

meta
#> Data Dictionary:
#> # A tibble: 6 × 8
#>   name         type    label    description units divby_modeling category_levels
#>   <chr>        <chr>   <chr>    <chr>       <chr> <chr>          <chr>          
#> 1 Sepal.Length Numeric none     none        none  none           none           
#> 2 Sepal.Width  Numeric none     none        none  none           none           
#> 3 Petal.Length Numeric none     none        none  none           none           
#> 4 Petal.Width  Numeric none     none        none  none           none           
#> 5 Species      Nominal none     none        none  none           setosa, versic…
#> 6 train_test   Nominal Train/t… none        none  none           train and test 
#> # ℹ 1 more variable: category_labels <chr>