Learn R Programming

interfacer (version 0.4.0)

imissing: Test if an iface parameter was supplied to a function

Description

As interfacer uses default values to specify the interface, a value will always be available, but it may be the iface spec itself. This is picked up by ivalidate calls and default value substituted if defined. This means that if you want to know that the parameter was not supplied you cannot use rlang::is_missing(...) as it will always think there is a default. base::missing(...) on the other hand will work as it differentiates between defaults and supplied values. This is a wrapper around base::missing to remind us to use it.

Usage

imissing(param)

Value

TRUE if the parameter was not supplied to the function

Arguments

param

a parameter name, as supplied to the enclosing function

Examples

Run this code
my_iface = iface(
  col1 = integer + group_unique ~ "an integer column",
  .default = tibble::tibble(col1 = 1:3)
)

x = function(df = my_iface, ...) {
  if(imissing(df)) {
    message("missing parameter")
  } else {
    message("parameter given")
  }
  df = ivalidate(df)
  return(df)
}

x() # missing parameter message, and function returns default value
try(x(iris)) # parameter given message but input will not validate

Run the code above in your browser using DataLab