3 Functions

3.1 Naming

As well as following the general advice for object names, strive to use verbs for function names:

3.3 return()

Only use return() for early returns. Otherwise, rely on R to return the result of the last evaluated expression.

If your function is called primarily for its side-effects (like printing, plotting, or saving to disk), it should return the first argument invisibly. This makes it possible to use the function as part of a pipe. print methods should usually do this, like this example from httr:


In code, use comments to explain the “why” not the “what” or “how”. Each line of a comment should begin with the comment symbol and a single space: #.