Skip to contents

This function converts a data.frame or a tibble into a datatagr object, where data are labelled and validated. The output will seem to be the same data.frame, but datatagr-aware packages will then be able to automatically use labelled fields for further data cleaning and analysis.

Usage

make_datatagr(x, ...)

Arguments

x

a data.frame or a tibble

...

<dynamic-dots> A named list with variable names in x as list names and the labels as list values. Values set to NULL remove the label. When specifying labels, please also see default_values.

Value

The function returns a datatagr object.

See also

Examples


x <- make_datatagr(cars,
  speed = "Miles per hour",
  dist = "Distance in miles"
)

## print result - just first few entries
head(x)
#> 
#> // datatagr object
#>   speed dist
#> 1     4    2
#> 2     4   10
#> 3     7    4
#> 4     7   22
#> 5     8   16
#> 6     9   10
#> 
#> labelled variables:
#>  speed - Miles per hour
#>  dist - Distance in miles 

## check labels
labels(x)
#> $speed
#> [1] "Miles per hour"
#> 
#> $dist
#> [1] "Distance in miles"
#> 

## Labels can also be passed as a list with the splice operator (!!!)
my_labels <- list(
  speed = "Miles per hour",
  dist = "Distance in miles"
)
new_x <- make_datatagr(cars, !!!my_labels)

## The output is strictly equivalent to the previous one
identical(x, new_x)
#> [1] TRUE