Initializes a DataDictionary object from a set of variables.
Variables should be made using numeric_variable() or nominal_variable()
and passed directly as arguments.
Arguments
- ...
Zero or more objects inheriting from A numeric variable or A nominal variable. If neither
...nor.listis supplied, an emptyDataDictionaryis created.- .list
A list of data variables. This argument allows
data_dictionaryto be used programmatically and is optional. It is intended to be used as an alternative to....- copy_on_modify
a logical value indicating whether
setfunctions should modify the dictionary in place or copy it then modify. The default isTRUEbecause dictionaries are almost always small and trivial to copy.
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>
