Description Usage Arguments Details Examples
Binary operators to get and set object attributes and environment members.
1 2 3 4 5 6 7 |
object |
An object. |
name |
An attribute's name. |
value |
An attribute's value. |
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.
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.