Function Arguments
In this page:
Function Arguments
Arguments are declared in the function's parameter list and can be passed either positionally or by name at the call site. Named arguments can be given in any order, which is especially useful for functions with many parameters. Mixing positional and named arguments is allowed, as long as positional ones come first.
Note: Calling with named arguments, like f(name = "Sam", times = 3), is more readable and order-independent.
Example: Function Arguments
greet <- function(name, times) {
for (i in 1:times) {
cat("Hello,", name, "!\n")
}
}
greet("Sam", 2)
greet(times = 1, name = "Priya")
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: