1_operators: Attribute and Environment Member Operators

Description Usage Arguments Details Examples

Description

Binary operators to get and set object attributes and environment members.

Usage

1
2
3
4
5
6
7
#object attributes
object %$% name
object %$% name <- value

#environment members
object %@% name
object %@% name <- value

Arguments

object

An object.

name

An attribute's name.

value

An attribute's value.

Details

The attribute operators are equivalent to calling the attr and attr<- functions.

Note that currently, they need to be inside parenthesis, for subsetting and function calls.

Also note that attribute names need to be quoted inside R packages.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#simple object
object <- 0

#set attributes
object %$% A <- 1
object %$% B <- 2
object %$% A %$% I <- 10
object %$% A %$% J <- 20

#get attributes
object %$% A
object %$% B
object %$% A %$% I
object %$% A %$% J

#quoted version
#(for R packages)
object %$% "A"
object %$% "B"

#this doesn't work
#object %$% A [1]

#however, this does work
(object %$% A) [1]

#function object
#(using lexical scope)
g <- function ()
{   A <- 2
    B <- 2
    function (x)
        A * B + x
}
f <- g ()

#get environment members
f %@% A
f %@% B

intoo documentation built on March 13, 2020, 1:45 a.m.

Related to 1_operators in intoo...