ABSTRACT

In chapter 6, you’ll learn how to turn your informal, working knowledge about functions into more rigorous, theoretical understanding. The tricks and techniques you will learn along the way will be important for understanding the more advanced topics discussed later in the book.

“Function fundamentals” describes the basics of creating a function, the three main components of a function, and the exception to many function rules: primitive functions (which are implemented in C, not R). “Function composition” discusses the strengths and weaknesses of the three forms of function composition commonly used in R code. “Lexical scoping” shows you how R finds the value associated with a given name, i.e. the rules of lexical scoping. “Lazy evaluation” is devoted to an important property of function arguments: they are only evaluated when used for the first time. “... (dot-dot-dot)” discusses the special ... argument, which allows you to pass on extra arguments to another function. “Exiting a function” discusses the two primary ways that a function can exit, and how to define an exit handler, code that is run on exit, regardless of what triggers it. “Function forms” shows you the various ways in which R disguises ordinary function calls, and how you can use the standard prefix form to better understand what’s going on.