chain: Chain functions into pipeline

Description Usage Examples

Description

Chain functions to make nested function calls easier to read. In brief, a %>% f(b) is equivalent to f(a, b). This function was exported from dplyr and originates from magrittr. See chain and %>% for more details.

Usage

1
a %>% b

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Not run: 
set.seed(3)
## Three ways to do a silly thing
# Nested functions
nested <- hclust(
  dist(
    cor(
      matrix(
        rnorm(100), 
        nrow = 4), 
      method = 'spearman'), 
    'minkowski'), 
  'complete')

# Temporary variable assignment (more readable)
temp   <- rnorm(100)
temp   <- matrix(temp, nrow = 4)
temp   <- cor(temp, method = 'spearman')
temp   <- dist(temp, 'minkowski')
temped <- hclust(temp, 'complete')

# Chained functions (most readable)
chained <- rnorm(100) %>% 
  matrix(nrow = 4) %>% 
  cor %>% 
  dist('minkowski') %>% 
  hclust('complete')

## End(Not run)

EricEdwardBryant/biogridr documentation built on May 6, 2019, 4:02 p.m.