Learn R Programming

intoo (version 0.4.0)

1_operators: Attribute and Environment Member Operators

Description

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

Usage

#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

Run this code
# NOT RUN {
#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
# }

Run the code above in your browser using DataLab