Skip to contents

Get the default value that is defined for a function's argument

Usage

getDefault(funName, argName, default = NULL, warn = TRUE)

Arguments

funName

Name of the function

argName

Name of the formal argument

default

Default value to use if no default value is stored for argument argName of function funName

warn

if TRUE (default) a message is given if no defaults are defined for the given function or argument and if default is returned instead.

Value

default value that is defined for the formal argument argName

of the user-defined function funName

See also

Examples

# Once you have defined a function...
hello <- function(firstName = getDefault("hello", "firstName")) {
  cat("Hello", firstName, "\n")
}

# ... you can define the default value for its arguments...
setDefault("hello", firstName = "Peter")
#> Error in get(parts[1]) : object 'hello' not found
#> Error: 'hello' does not seem to be a function!

# ... and read it back with getDefault()...
getDefault("hello", "firstName")
#> Error in get(parts[1]) : object 'hello' not found
#> There are no defaults for function 'hello' defined! Use setDefault('hello', firstName = ...) to set a default value. Also, 'hello' does not seem to be a function!  Returning the default value: 
#> NULL