Functions
Defining a Function
Use the function
keyword to define a function.
Parameters and Arguments
You can pass data into functions using parameters.
Return Values
Use return()
to send a result back to the caller.
Default Parameter Values
You can give parameters default values in the function definition.
Named Arguments
You can pass arguments by name, in any order.
Variable Number of Arguments
Use ...
for an arbitrary number of arguments.
You can also pass named arguments using ...
and access them with list(...)
.
Functions Returning Multiple Values
Return multiple values using a list.
Common Errors
Some frequent errors encountered when dealing with Functions in R.