Using multiple functions after each other

To create a sequence of functions where each function uses the output of the previous function as input, you can nest them e.g.:

y <- round(log(x),digits=1)

First R will run what’s inside the round brackets: the log() function using variable x as input, then R will use the output of the log() function as input in the round() function.

Alternatively you can use %>% (the pipe operator) from the magrittr package. This operator will forward a variable or the result of a function as input to the next function e.g.:

library(magrittr)
y <- x %>% log %>% round(digits=1)

will give exactly the same result as the code above. First variable x will be passed as input to the log function, then the result of log will be passed as input to the round function.

Both systems are being used, some people prefer nesting, others prefer piping.