op-get-attr: Infix attribute accessor and setter

op-get-attrR Documentation

Infix attribute accessor and setter

Description

This operator extracts or sets attributes for regular objects and S4 fields for S4 objects.

Usage

x %@% name

x %@% name <- value

Arguments

x

Object

name

Attribute name

value

New value for attribute name.

Examples

# Unlike `@`, this operator extracts attributes for any kind of
# objects:
factor(1:3) %@% "levels"
mtcars %@% class

mtcars %@% class <- NULL
mtcars

# It also works on S4 objects:
.Person <- setClass("Person", slots = c(name = "character", species = "character"))
fievel <- .Person(name = "Fievel", species = "mouse")
fievel %@% name

rlang documentation built on June 22, 2024, 9:31 a.m.