Named Arguments (R)
Named arguments let you pass values to a function by name (arg = value) instead of by position. R matches named arguments first, then fills the rest by position, and supports partial name matching.
R
In a call like plot(x, y, col = "red", main = "Title"), col and main are named arguments. Naming makes calls self-documenting and lets you skip over optional arguments without supplying every preceding one — especially useful for R functions that have many parameters with defaults.
R's matching order is: exact names first, then partial names (you can write mea = TRUE for mean if unambiguous, though this is discouraged for clarity), then remaining arguments by position. Because of this, named arguments can appear in any order.
Naming arguments is good practice for any call beyond one or two simple positional values; it prevents bugs from passing things in the wrong slot and makes code far easier to read. Functions also collect extra named arguments via the ... (dots) parameter.
Syntax
round(3.14159, digits = 2)
seq(from = 1, to = 10, by = 2)Examples
R
print(round(3.14159, digits = 2))
print(seq(from = 0, to = 10, by = 5))
print(rep("a", times = 3))Output:
[1] 3.14
[1] 0 5 10
[1] "a" "a" "a"