Skip to contents

Initializes a DataDictionary object from a set of variables. Variables should be made using numeric_variable() or nominal_variable() and passed directly as arguments.

Usage

data_dictionary(..., .list = NULL, copy_on_modify = TRUE)

Arguments

...

Zero or more objects inheriting from A numeric variable or A nominal variable. If neither ... nor .list is supplied, an empty DataDictionary is created.

.list

A list of data variables. This argument allows data_dictionary to be used programmatically and is optional. It is intended to be used as an alternative to ....

copy_on_modify

a logical value indicating whether set functions should modify the dictionary in place or copy it then modify. The default is TRUE because dictionaries are almost always small and trivial to copy.

Value

A data dictionary object

Details

At most one of ... and .list should be specified. Calling data_dictionary() with no arguments creates an empty dictionary, which can be populated later with bind_variables().

Examples


age_years <- numeric_variable(
  name = "age",
  label = "Age of participant",
  units = "years"
)

gender <- nominal_variable(
  name = "gender",
  label = "Gender of participant",
  category_levels = c("M", "F"),
  category_labels = c("Male", "Female")
)

dd <- data_dictionary(age_years, gender)
print(dd)
#> Data Dictionary:
#> # A tibble: 2 × 8
#>   name   type    label          description units divby_modeling category_levels
#>   <chr>  <chr>   <chr>          <chr>       <chr> <chr>          <chr>          
#> 1 age    Numeric Age of partic… none        years none           none           
#> 2 gender Nominal Gender of par… none        none  none           M and F        
#> # ℹ 1 more variable: category_labels <chr>

dd <- data_dictionary(.list = list(age_years, gender))
print(dd)
#> Data Dictionary:
#> # A tibble: 2 × 8
#>   name   type    label          description units divby_modeling category_levels
#>   <chr>  <chr>   <chr>          <chr>       <chr> <chr>          <chr>          
#> 1 age    Numeric Age of partic… none        years none           none           
#> 2 gender Nominal Gender of par… none        none  none           M and F        
#> # ℹ 1 more variable: category_labels <chr>

# An empty dictionary can also be created and populated later
dd_empty <- data_dictionary()
print(dd_empty)
#> Data Dictionary:
#> # A tibble: 0 × 8
#> # ℹ 8 variables: name <chr>, type <chr>, label <chr>, description <chr>,
#> #   units <chr>, divby_modeling <chr>, category_levels <chr>,
#> #   category_labels <chr>