Every function in R has three important characteristics:
- a body (the code inside the function) - body()
- arguments (the list of arguments which controls how you can call the function) - formals()
- an environment (the “map” of the location of the function’s variables) - environment()
You can see all three parts if you type the name of the function without brackets. Exceptions are primitives. Primitive functions, like sum(), call C code directly with .Primitive() and contain no R code. Therefore their formals(), body(), and environment() are all NULL.
Functions
Function Arguments
Arguments are matched
- first by exact name (perfect matching)
- then by prefix matching
- and finally by position.
By default, R function arguments are lazy, they are only evaluated if they are actually used: