Writing Functions and Scripts
Samuel E. Buttrey · 2017
Functions and scripts are two methods by which we can do repetitive tasks easily. They have similar goals, but they operate in different ways. There are several aspects to a function, and data handlers will need to understand all of them to use functions properly. These include the arguments, the return value, and side effects. This chapter describes the different pieces of an R function. A script is a text file that contains R commands and possibly other lines as well. Scripts to store a lot of the commands, and data handlers often run them bit by bit, interactively, a few lines at a time. A function or script will very often need to interact with the operating system. The chapter gives a couple of examples of the different ways that R can interact with the operating system, separately from the chore of actually acquiring data from an outside source.