| setDefault | R Documentation |
Define the default value for a function's argument
setDefault(funName, ...)
funName |
Name of the function |
... |
default value assignments in the form of |
getDefault
## Not run:
# 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()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.