tee: Tee operator

Description Arguments See Also Examples

Description

This package uses the "tee" operator (%T>%) to modify objects.

Arguments

lhs, rhs

An object and a function.

See Also

%T>%, pipe.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# the tee operator returns the left-hand side of the result and can be
# useful when dealing with mutable objects. In this example we want
# to use the function "f" to modify the object "e" and capture the 
# result

# create an empty environment
e <- new.env()

# create a function to modify an environment and return NULL
f <- function(x) {x$a <- 5; return(NULL)}

# if we use the pipe operator we won't capture the result since "f"() 
# returns a NULL
e2 <- e %>% f()
print(e2)

# but if we use the tee operator then the result contains a copy of "e"
e3 <- e %T>% f()
print(e3)

prioritizr/prioritizrutils documentation built on May 25, 2019, 12:20 p.m.