Skip to contents

Add attributes to an object, optionally overwriting attributes that already exist.

Usage

set_attributes(x, attributes, overwrite = FALSE)

Arguments

x

(object)
An R object.

attributes

(named list)
A named list of attributes to set.

overwrite

(logical(1))
Should be existing attributes overwritten?

Value

The object with updated attributes.

x with the given attributes attached.

Examples

   set_attributes(NA, list("attribute 1" = 1))
#> [1] NA
#> attr(,"attribute 1")
#> [1] 1
   set_attributes(NA, list("attribute 1" = 2))
#> [1] NA
#> attr(,"attribute 1")
#> [1] 2
   set_attributes(NA, list("attribute 1" = 2, overwrite = TRUE))
#> [1] NA
#> attr(,"attribute 1")
#> [1] 2
#> attr(,"overwrite")
#> [1] TRUE