ABSTRACT

This chapter introduces a set of basic programming constructs, which are the building blocks of most programs. Some of these tools are used by practically all programming languages, for example, conditional execution by if statements, and looped execution by for and while statements. Other tools, such as vector-based programming, are more specialised, but are just as important for efficient R coding. An implication is that code that seems to be efficient in another language may not be efficient in R. Therefore previously established coding practices may lead to inefficient, or worse, ugly code in R. We revisit programming in R in chapters 5 and 8.