camr_add_attribute: Add Attribute to R Object

View source: R/R04-Data_wrangling.R

camr_add_attributeR Documentation

Add Attribute to R Object

Description

Function to add an attribute to an R object while preserving any existing attributes (especially useful for not overwriting attributes for dates to function properly).

Usage

camr_add_attribute(x, attribute, label)

Arguments

x

An R object.

attribute

The element to add as an attribute.

label

The label to use in the list of attributes.

Value

The R object with updated attributes.

Author(s)

Kevin Potter

Examples


x <- 1:3
x <- x |> camr_add_attribute( "Hello world", "example" )
print( x )

# Preserves existing attributes
x <- as.Date( c( "2000-01-01", "2010-06-15", "2020-12-25" ) )
x <- x |> camr_add_attribute( "Hello world", "example" )
print( class( x ) )
print( attributes( x )$example )


rettopnivek/camrprojects documentation built on March 26, 2024, 9:17 a.m.