Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

syntactic-sugar

Syntactic Sugar for Setting Annotations and Attributes


Description

The operator %#% can be used to attach a description annotation to an object. %##% can be used to attach a character vector of annotations to an object. %@% returns the attribute with the name given as second argument. With %@% it is also possible to assign attributes.

Usage

x %#% descr
  x %##% annot
  x %@% nm
  x %@% nm <- value

Arguments

x

an object, usually and item or a vector.

descr

a character string

annot

a named character vector; its contents are added to the "annotation" attribute of x. Existing elements are kept.

nm

a character string, the name of the attribute being set or requested.

value

any kind of object that can be attached as an attribute.

Examples

test1 <- 1 %#% "One"
# This is equivalent to:
# test <- 1
# description(test) <- "One"
description(test1)
# Results in "One"

# Not that it makes sense, but ...
test2 <- 2 %##% c(
                    Precedessor = 0,
                    Successor   = 2
                 )
# This is equivalent to:
# test2 <- 2
# annotation(test2) <- c(
#                    Precedessor = 0,
#                    Successor   = 2
#                 )
annotation(test2)

# The following examples are equivalent to
# attr(test2,"annotation")
test2 %@% annotation

test2 %@% "annotation"

test2 %@% another.attribute <- 42
# This is equivalent to attr(test2,"another.attribute") <- 42

attributes(test2)

memisc

Management of Survey Data and Presentation of Analysis Results

v0.99.27.3
GPL-2
Authors
Martin Elff (with contributions from Christopher N. Lawrence, Dave Atkins, Jason W. Morgan, Achim Zeileis)
Initial release
2020-11-18

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.