setDefault: Define the default value for a function's argument

View source: R/default_main.R

setDefaultR Documentation

Define the default value for a function's argument

Description

Define the default value for a function's argument

Usage

setDefault(funName, ...)

Arguments

funName

Name of the function

...

default value assignments in the form of key = value pairs

See Also

getDefault

Examples

## 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)

KWB-R/kwb.default documentation built on June 17, 2022, 3:04 a.m.