getAttribute: Safely get the Attribute of an Object

View source: R/attribute.R

getAttributeR Documentation

Safely get the Attribute of an Object

Description

Safely get the attribute of an object. An error is given if the attribute does not exist (and do.stop = TRUE)

Usage

getAttribute(x, attributeName, do.stop = TRUE)

Arguments

x

object from which to take the attribute

attributeName

name of the attribute to be returned

do.stop

if TRUE (default) an error is raised if the attribute does not exist.

Examples


x <- structure(1, a = 2)
# getAttribute(x, "b") # gives a clear error message
identical(getAttribute(x, "a"), attr(x, "a")) # is TRUE

# Get an attribute's attribute by means of a "path" notation
y <- structure(1, a = structure(2, b = 3))
z <- structure(4, y = y)

str(y)
str(z)

kwb.utils::getAttribute(y, "a/b")
kwb.utils::getAttribute(z, "y/a/b")


KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.