Description Usage Arguments Details Value Examples
%@%
is an infix-form wrapper for the attr
function.
1 2 3 4 5 6 7 | x %@% attribute
x %try@% attribute
SetAttribute(x, attribute, value)
x %@% attribute <- value
|
x |
An object with attributes |
attribute |
A character string that names an attribute of the object. |
value |
a new value for an attribute |
A Trial
object is a data-frame of looking data, and metadata
about the trial like the images onscreen or duration of the carrier phrase
are stored in attributes attached to the data-frame. The functions described
below making working with attributes a little easier.
%@%
is a utility function for getting the value of an attribute
from an R object. This is a wrapper for the built-in function attr
.
%@%.list
applies %@%
onto each object in a list of R
objects. Therefore, %@%
cannot grab attributes of lists, unless
they are lists within lists. This is weird; maybe I should fix this.
Attributes can be set two ways:
x <- SetAttribute(x, attribute, value)
x %@% attribute <- value
If the object is a TrialList
then then assignment is vectorized,
meaning that each object (i.e., Trial
) is updated with the
value
(which is recycled as needed).
%try@%
replaces NULL
values with NA
if the attribute is
missing.
The value in the attribute slot of object, or the values of the attribute for each element element in a list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Cat <- function(name, owner) {
structure(list(Name = name), Owner = owner, class = "cat")
}
kiki <- Cat("Kiki", "AML")
nooper <- Cat("Nooper", "TJM")
kiki %@% "Owner"
# [1] "AML"
list(nooper, kiki) %@% "Owner"
# [1] "TJM" "AML"
# Setting/overwriting a attribute
nooper %@% "Owner" <- NA
list(nooper, kiki) %@% "Owner"
# [1] NA "AML"
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.