Attributes a valueType to an object, that can be a vector, or in a data frame using dplyr::mutate.

as_valueType(x, valueType = "text")

Arguments

x

Object to be coerced. Can be a vector.

valueType

A character string of the valueType used to coerce x.

Value

The object coerced accordingly to the input valueType.

Details

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_DEMO provided by the package

dataset <- madshapR_DEMO$dataset_TOKYO
as_valueType(head(dataset$dob),'date')

# as_valueType is compatible with tidyverse philosophy
library(dplyr)
mtcars %>% mutate(cyl = as_valueType(cyl,'integer')) %>% head()

}
#>                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
#> Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
#> Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
#> Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
#> Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
#> Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
#> Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1