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.

Return statements should always be on their own line because they have important effects on the control flow. See also inline statements.

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: