ivalidate | R Documentation |
ivalidate(...)
is intended to be used within a function to check the validity of a data
frame parameter (usually the first parameter) against an ispec
which is
given as a default value of a formal parameter.
ivalidate(df = NULL, ..., .imap = imapper(), .prune = FALSE, .default = NULL)
df |
a dataframe - if missing then the first parameter of the calling function is assumed to be a dataframe. |
... |
not used but |
.imap |
a set of mappings as an |
.prune |
get rid of excess columns that are not in the spec. |
.default |
a default dataframe conforming to the specification. This overrides any defaults defined in the interface specification |
a dataframe based on df
with validity checks passed and .imap
mappings applied if present
x = function(df = iface(col1 = integer ~ "an integer column" ), ...) {
df = ivalidate(...)
return(df)
}
input=tibble::tibble(col1 = c(1,2,3))
x(input)
# This fails because col1 is not coercable to integer
input2=tibble::tibble(col1 = c(1.5,2,3))
try(x(input2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.