For convenience we sometimes want to strip some or all attributes in a oneliner.

SetAttr(x, attr, attr_val)
StripAttr(x, attr_names = NULL)

Arguments

x

the object whose attributes should be removed or to which an attribute should be added.

attr

name of a new attribute

attr_val

value for the new attribute attr

attr_names

a vector with attribute names, which will be removed. Leaving the default to NULL will cause all the attributes to be deleted.

Value

the object x without the attributes contained in attr_names

Author

Andri Signorell <andri@signorell.net>

See also

Examples

x <- runif(10)
x <- SetAttr(x, 
             attr=c("some_attr", "other_attr"),
             attr_val=c("First attribute", "Second attribute"))

# strip only single
StripAttr(x, "other_attr")
#>  [1] 0.9066705 0.0505451 0.4329996 0.9027497 0.1559692 0.5348265 0.1899625
#>  [8] 0.4968403 0.3587977 0.7816822
#> attr(,"some_attr")
#> [1] "First attribute"

# strip all attributes
StripAttr(x)
#>  [1] 0.9066705 0.0505451 0.4329996 0.9027497 0.1559692 0.5348265 0.1899625
#>  [8] 0.4968403 0.3587977 0.7816822