Function Argument
Function Argument
> hello.person("Bob")
> hello.person("Sarah")
The argument name can be used as a variable inside the function (it does not exist
outside the function). It can also be used like any other variable and as an argument to
further function calls.
We can add a second argument to be printed as well. When calling functions with more
than one argument, there are two ways to specify which argument goes with which value,
either positionally or by name.
> # by name
> hello.person(first="Jared", last="Lander")
Being able to specify the arguments by name adds a lot of flexibility to calling functions.
Even partial argument names can be supplied, but this should be done with care.
> hello.person(fir="Jared", l="Lander")
> # now build hello.person with ... so that it absorbs extra arguments
> hello.person <- function(first, last="Doe", ...)
+ {
+ print(sprintf("Hello %s %s", first, last))
+ }
> # call hello.person with an extra argument
> hello.person("Jared", extra="Goodbye")