Skip to contents

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

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 safeframe object.

See also

make_safeframe() to create a safeframe object

Examples


## create a safeframe
x <- make_safeframe(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"
#>