Chapter 8
Putting the Fun in Functions
In This Chapter
Automating your work with functions
Playing with arguments
Finding objects within the functions
Working with methods
Automating your work is probably the number one reason why you use a programming language. You can get pretty far with the built-in functions of R in combination with scripts, but scripts aren’t very flexible when dealing with variable input. Luckily, R allows you to write your own custom functions (for example, to automate the cleaning of your data, to apply a series of analyses with one command, or to construct custom plots).
The functions that you write yourself are essentially the same as many of the built-in functions — they are first-class citizens. In this chapter, you discover how to write and work with functions in R.
Moving from Scripts to Functions
Going from a script to a function doesn’t take much effort at all. A function is essentially a piece of code that is executed consecutively and without interruption. In that way, a function doesn’t differ that much from a script run using the source() function, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access