itest | R Documentation |
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.
itest(df = NULL, iface = NULL, .imap = imapper())
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 |
.imap |
an optional mapping specification produced by |
TRUE if the dataframe is conformant, FALSE otherwise
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.