© Thomas Mailund 2017

Thomas Mailund, Metaprogramming in R, 10.1007/978-1-4842-2881-4_1

1. Anatomy of a Function

Thomas Mailund

(1)Aarhus N, Denmark

Everything you do in R involves defining functions or calling functions. You cannot do any action without evaluating some function or other. Even assigning values to variables or subscripting vectors or lists involves evaluating functions. But functions are more than just recipes for how to perform different actions; they are also data objects in themselves, and there are ways of probing and modifying them.

Manipulating Functions

If you define a simple function like the following, you can examine the components it consists of:

f <- function(x) x

There are three parts to a function: its formal parameters, ...

Get Metaprogramming in R: Advanced Statistical Programming for Data Science, Analysis and Finance now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.