atsign: Overloaded infix @ for attribute access

Description Usage Arguments Details Value See Also Examples

Description

The at-sign, '@', is normally used with S4 objects for slot access. These functions allow the use of infix @ on non-S4 objects to get and set attributes.

Usage

1
2
3
object@name

object@name <- value

Arguments

object

A non-S4 object.

name

The character-string name of the attribute to access, quoted or not.

value

The value of the attribute to be set.

Details

The right-hand-side of the @ operator (the name argument) need not be quoted. It is converted to a literal character string by computation on the language using match.call. Attribute names must be matched exactly.

These functions check whether their left-hand argument is an S4 object, and if so, pass it through to the slot function, leaving the original use of @ for slot access unaffected.

Value

The value of the attribute.

See Also

copyatts

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
mu <- 3
sigma <- 2
x <- rnorm(10, mean=mu, sd=sigma)

attr(x, "mu") <- mu
print(attr(x, "mu"))

x@sigma <- sigma
print(x@sigma)

print(x)
x@mu <- NULL
x@mu_s <- mean(x)
x

sethmcg/climod documentation built on Nov. 19, 2021, 11:12 p.m.