Skip to contents

This function changes the labels of a datatagr object, using the same syntax as the constructor make_datatagr().

Usage

set_labels(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

make_datatagr() to create a datatagr object

Examples


## create a datatagr
x <- make_datatagr(cars, speed = "Miles per hour")
labels(x)
#> $speed
#> [1] "Miles per hour"
#> 

## add new labels and fix an existing one
x <- set_labels(x, dist = "Distance")
labels(x)
#> $speed
#> [1] "Miles per hour"
#> 
#> $dist
#> [1] "Distance"
#> 

## remove labels by setting them to NULL
old_labels <- labels(x)
x <- set_labels(x, speed = NULL, dist = NULL)
labels(x)
#> $speed
#> [1] ""
#> 
#> $dist
#> [1] ""
#> 

## setting labels providing a list (used to restore old labels here)
x <- set_labels(x, !!!old_labels)
labels(x)
#> $speed
#> [1] "Miles per hour"
#> 
#> $dist
#> [1] "Distance"
#>