get_attribute: Get Attribute From List or Data Frame

Description Usage Arguments Value Examples

View source: R/miscutils.R

Description

select a named element from a list or data.frame with default for missed values

Usage

1
get_attribute(x, attribute, default = NULL)

Arguments

x

a list-like object (e.g. data.frame)

attribute

the name or index of an element in x

default

value to return if attribute is missed or error (NULL)

Value

the value of attribute from x or default

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
y <- list('a' = 1)
x <- data.frame('b' = 2)
get_attribute(y, 'a', 2) # 1
get_attribute(y, 'b', 1) # 1
get_attribute(x, 'a', 2) # 2
get_attribute(x, 'b', 1) # 2

## End(Not run)

duncankmckinnon/OKdplyr documentation built on Nov. 30, 2020, 1:13 a.m.