Get the default value that is defined for a function's argument
Source:R/default_main.R
getDefault.Rd
Get the default value that is defined for a function's argument
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 functionfunName
- warn
if
TRUE
(default) a message is given if no defaults are defined for the given function or argument and ifdefault
is returned instead.
Value
default value that is defined for the formal argument argName
of the user-defined function funName
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