Define the default value for a function's argument
Arguments
- funName
Name of the function
- ...
default value assignments in the form of
key = value
pairs
Examples
if (FALSE) {
# This will lead to an error if funtion "hello" is not defined
setDefault("hello", firstName = "Peter")
# Define the function and use getDefault instead of a constant default value
hello <- function(
firstName = getDefault("hello", "firstName"),
lastName = getDefault("hello", "lastName")
)
{
cat(paste0("Hello ", firstName, " ", lastName, "!\n") )
}
# Now you can define the argument defaults
setDefault("hello", firstName = "Don", lastName = "Quichote")
# If you call the function without arguments, the defaults are used
hello()
# You can now change the defaults without changing the function definition
setDefault("hello", firstName = "Mona", lastName = "Lisa")
hello()
}