Learn R Programming

interfacer (version 0.3.3)

itest: Test dataframe conformance to an interface specification.

Description

ivalidate throws errors deliberately however sometimes dealing with invalid input may be desirable. itest is generally designed to be used within a function which specifies the expected input using iface, and allows the function to test if its given input is conformant to the interface.

Usage

itest(df = NULL, iface = NULL, .imap = imapper())

Value

TRUE if the dataframe is conformant, FALSE otherwise

Arguments

df

a dataframe to test. If missing the first parameter of the calling function is assumed to be the dataframe to test.

iface

an interface specification produced by iface(). If missing this will be inferred from the current function signature.

.imap

an optional mapping specification produced by imapper()

Examples

Run this code
if (rlang::is_installed("ggplot2")) {
  i_diamonds = iface( 
    color = enum(D,E,F,G,H,I,J,extra) ~ "the colour", 
    price = integer ~ "the price"
  )
  
  # Ad hoc testing
  itest(ggplot2::diamonds, i_diamonds)
  
  # Use within function:
  x = function(df = i_diamonds) {
    if(itest()) message("PASS!")
  }
  
  x(ggplot2::diamonds)
}

Run the code above in your browser using DataLab