It is sometimes useful to take variable valueType’s from a dataset and attribute them to the associated data dictionary, or vice versa. valueType_self_adjust() takes the valueType guessed of the input and attributes it to itself. The parameter can be either a dataset or a data dictionary. Depending on the input provided, the valueType replaced is either in the 'valueType' column of the data dictionary or cast to a column in the dataset. The possible values of the valueTypes returned are 'date','datetime', 'boolean', 'integer', 'decimal', and text'.

valueType_self_adjust(...)

Arguments

...

Object that can be either a dataset or a data dictionary.

Value

Either a data frame, identifying the dataset, or a list of data frame(s) identifying a data dictionary, depending which the input refers to.

Details

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.

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.

The valueType is a declared property of a variable that is required in certain functions to determine handling of the variables. Specifically, valueType refers to the OBiBa data type of a variable. The valueType is specified in a data dictionary in a column 'valueType' and can be associated with variables as attributes. Acceptable valueTypes include 'text', 'integer', 'decimal', 'boolean', datetime', 'date'. The full list of OBiBa valueType possibilities and their correspondence with R data types are available using valueType_list. The valueType can be used to coerce the variable to the corresponding data type.

Examples

{

# use madshapR_examples provided by the package

###### Example 1: The valueType of a dataset can be adjusted. each column is
# evaluated as whole, and the best valueType match found is applied. If 
# there is no better match found, the column is left as it is.

dataset <- madshapR_examples$`dataset_example`
dataset <- valueType_self_adjust(dataset["gndr"])
head(dataset)

###### Example 2: Aany data frame can be dataset by definition
dataset <- valueType_self_adjust(mtcars)
head(dataset)

}
#> # A tibble: 6 × 11
#>     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>   <dbl> <int> <dbl> <int> <dbl> <dbl> <dbl> <int> <int> <int> <int>
#> 1  21       6   160   110  3.9   2.62  16.5     0     1     4     4
#> 2  21       6   160   110  3.9   2.88  17.0     0     1     4     4
#> 3  22.8     4   108    93  3.85  2.32  18.6     1     1     4     1
#> 4  21.4     6   258   110  3.08  3.22  19.4     1     0     3     1
#> 5  18.7     8   360   175  3.15  3.44  17.0     0     0     3     2
#> 6  18.1     6   225   105  2.76  3.46  20.2     1     0     3     1