Learn R Programming

wrapr (version 1.1.1)

named_map_builder: Named map builder.

Description

Set names of right-argument to be left-argument, and return right argument. Has a special case for length-1 name sets. Called from := operator.

Usage

named_map_builder(names, values)

":="(names, values)

Arguments

names

names to set.

values

values to assign names to (and return).

Value

values with names set.

Examples

Run this code
# NOT RUN {

c('a' := '4', 'b' := '5')
# equivalent to: c(a = '4', b = '5')

c('a', 'b') := c('1', '2')
# equivalent to: c(a = '1', b = '2')

# the important example
name <- 'a'
name := '5'
# equivalent to: c('a' = '5')

# fn version:
#  applied when right side is {}
#  or when left side is of class formula.

g <- x~y := { x + 3*y }
g(1,100)

f <- ~x := x^2
f(7)

# }

Run the code above in your browser using DataLab