4 Understanding the tools you’ll use: Functions

This chapter covers

  • Repeating operations with functions
  • The boundaries of where things are defined (scope)
  • Messages, warnings, and errors, and how to deal with them
  • Testing that your code does what you think it does

The true power of a programming language arises when you can tell the computer to do something and that request is simpler than just doing the work ourselves. Any time you want to calculate something more than once, it’s potentially a good idea to wrap the code up into a meaningful expression that can be reevaluated with a different (or even the same) input.

You’ll quickly see that functions are the standard method of achieving this goal in R. Once errors inevitably arise, you’ll ...

Get Beyond Spreadsheets with R now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.