Generates a data dictionary from a dataset. If the dataset variables have no associated metadata, a minimum data dictionary is created by using variable attributes.

data_dict_extract(dataset, as_data_dict_mlstr = TRUE)

Arguments

dataset

A dataset object.

as_data_dict_mlstr

Whether the input data dictionary should be coerced with specific format restrictions for compatibility with other Maelstrom Research software. TRUE by default.

Value

A list of data frame(s) representing metadata of the dataset variables.

Details

A dataset is a data table containing variables. A dataset object is a data frame and can be associated with a data dictionary. If no data dictionary is provided with a dataset, a minimum workable data dictionary will be generated as needed within relevant functions. Identifier variable(s) for indexing can be specified by the user. The id values must be non-missing and will be used in functions that require it. If no identifier variable is specified, indexing is handled automatically by the function.

A data dictionary contains the list of variables in a dataset and metadata about the variables and can be associated with a dataset. A data dictionary object is a list of data frame(s) named 'Variables' (required) and 'Categories' (if any). To be usable in any function, the data frame 'Variables' must contain at least the name column, with all unique and non-missing entries, and the data frame 'Categories' must contain at least the variable and name columns, with unique combination of variable and name.

The object may be specifically formatted to be compatible with additional Maelstrom Research software, in particular Opal environments.

Examples

{

# use madshapR_DEMO provided by the package

###### Example 2: extract data dictionary from any dataset (the 
# data dictionary will be created upon attributes of the dataset. Factors 
# will be considered as categorical variables)
data_dict_extract(iris)

}
#> $Variables
#> # A tibble: 5 × 3
#>   name         label        valueType
#>   <chr>        <chr>        <chr>    
#> 1 Sepal.Length Sepal.Length decimal  
#> 2 Sepal.Width  Sepal.Width  decimal  
#> 3 Petal.Length Petal.Length decimal  
#> 4 Petal.Width  Petal.Width  decimal  
#> 5 Species      Species      text     
#> 
#> $Categories
#> # A tibble: 3 × 4
#>   variable name       label      missing
#>   <chr>    <chr>      <chr>      <lgl>  
#> 1 Species  setosa     setosa     FALSE  
#> 2 Species  versicolor versicolor FALSE  
#> 3 Species  virginica  virginica  FALSE  
#> 
#> attr(,"madshapR::class")
#> [1] "data_dict_mlstr"