att_help: Attribute Management Functions

View source: R/att.R

att_helpR Documentation

Attribute Management Functions

Description

Get attributes of an object, names of attributes of an object, determine whether there is a named attribute of an object, add attributes to an object, modify values of attributes of an object, and remove attributes of an object.

Usage

att_help()

att(.x, ..., .a = FALSE)

atts(x)

att_names(x)

is_att(x, name)

add_att(.x, ...)

set_att(.x, ...)

rm_att(x, ...)

xatt(x, ...)

rm_atts(x)

xatts(x)

Arguments

...

For add_att and set_att, named arguments. For rm_att/xatt and att optional character objects (also optionally pipe delimited). When none are provided, indicates all attributes of .x.

.a

TRUE or FALSE indicating whether to atomize the result and convert the resulting vector to character.

x, .x

An R object.

name

A complete character scalar (?cmp_chr_scl).

Functions

  • att(): Get the attributes of .x named in ..., optionally atomizing the result when .a = TRUE. When there are no ... args, gets all attributes of .x. Return value varies depending on x and ....

  • atts(): Gets the attributes of x. Thinly wraps attributes(x). Returns either NULL or a named list.

  • att_names(): Gets the names of attributes of x. Thinly wraps names(attributes(x)). Returns either NULL or a character vector.

  • is_att(): Evaluates whether name is the name of an attribute of x. Returns a logical scalar.

  • add_att(): Adds attributes to .x as specified in ... where attribute names are the names of ... args and attribute values are the values of ... args. Returns x with added attributes as specified in ....

  • set_att(): Sets attributes of .x to the values specified in ... where names of modified attributes are the names of ... args and the values of modified attributes are the values of ... args. Returns x with modified attribute values.

  • rm_att(): Removes from x any attributes named in ... (where ... is atomized to a character vector and split along pipes ('|')). When there are no ... args, removes all attributes from x. Returns x with the specified attributes removed.

  • xatt(): An alias for rm_att.

  • rm_atts(): Removes all attributes from x. Returns x with all attributes removed.

  • xatts(): An alias for rm_atts.

Examples

egAtt <- function() {
  x1 <- matrix(
    NA,
    nrow = 2,
    ncol = 2,
    dimnames = list(rows = c("r1", "r3"), cols = c("c1", "c2"))
  )
  x2 <- add_att(x1, added = "added attribute")
  x3 <- set_att(x2, added = "new attribute value")
  x4 <- rm_att(x2, "added")
  x5 <- xatt(x2)
  x6 <- xatts(x2)
  list(
    x1 = x1, x2 = x2, x3 = x3, x4 = x4, x5 = x5, x6 = x6,
    att.names.x1 = att_names(x1), att.names.x2 = att_names(x2),
    att.names.x3 = att_names(x3), att.names.x4 = att_names(x4),
    att.names.x5 = att_names(x5), att.names.x6 = att_names(x6),
    atts.x1 = atts(x1), atts.x2 = atts(x2), atts.x3 = atts(x3),
    atts.x4 = atts(x4), atts.x5 = atts(x5), atts.x6 = atts(x6),
    att.x2.added = att(x2, "added"), att.x2.a = att(x2, .a = T),
    att.x2 = att(x2), is.att.x1.added = is_att(x1, "added"),
    is.att.x2.added = is_att(x2, "added")
  )
}
egAtt <- egAtt()
egAtt

j-martineau/uj documentation built on Sept. 14, 2024, 4:40 a.m.