Chapter 12
Writing Your Own Scripts: Beginning to Program
What You Will Learn In This Chapter:
- How to store series of commands as snippets to be used with copy/paste
- How to make your own help file
- How to create simple customized functions
- How to edit, store, and recall customized functions
- How to add notes/annotations to your scripts
- How to create complex program code
Because R is a programming language, you have great flexibility in the approach you can take to running it. When you first begin to use R you will probably type commands directly from the keyboard. Later, as you become more confident, you will likely use snippets of commands stored in other areas, like a text file. The next step is to create simple functions that carry out something useful; you can call up these functions time and time again, and can save a lot of typing and effort. As your confidence and ability grow you will move on to creating larger scripts, that is, sets of R commands stored in a file that you can execute at any time.
Scripts can be especially useful because they enable you to prepare complex or repetitive tasks, which you can bring into operation at any time. Indeed, R is built along these lines, and you can think of the program as a bundle of scripts; by making your own you are simply increasing the usefulness of R and bending it to meet your own specific requirements.
Programming R is a wide subject in its own right. This chapter introduces you to the basic ideas so that you can set off ...
Get Beginning R: The Statistical Programming Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.