Default Arguments
In this page:
Default Arguments
A parameter can have a default value specified in the function definition, making it optional at the call site. If the caller doesn't supply that argument, the default is used instead. Default values can even reference other parameters of the same function.
Note: Place parameters with defaults after required parameters, mirroring the convention used in most other languages.
Example: Default Arguments
greet <- function(name, greeting = "Hello") {
cat(greeting, ",", name, "!\n")
}
greet("Alice")
greet("Bob", "Welcome")
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: