ABSTRACT

Functions are the heart of S language and writing or modifying them is the most important part of creating new capabilities based on S. This chapter discusses how to write functions. A function in S can have any number of arguments, and the computation that is done by it can be anything expressible in S. A call to an S function does not need to supply all the formal arguments in the function definition. Any subset of the formal arguments can be supplied, either by position or by name. The function can handle missing arguments two ways; either by providing a default expression in the argument list of the definition, or by testing explicitly for missing arguments. Functions can be defined to take a variable number of arguments. Thinking for a while before implementing a new function can produce a clearer, more easily implemented idea of what the function is intended to do and how the function can be written.