assert_data_frame: Is an Argument a Data Frame?

Description Usage Arguments Value Author(s) Examples

View source: R/assertions.R

Description

Checks if an argument is a data frame and (optionally) whether is contains a set of required variables

Usage

1
assert_data_frame(arg, required_vars = NULL, optional = FALSE)

Arguments

arg

A function argument to be checked

required_vars

A list of variables created using vars()

optional

Is the checked parameter optional? If set to FALSE and arg is NULL then an error is thrown

Value

The function throws an error if arg is not a data frame or if arg is a data frame but misses any variable specified in required_vars. Otherwise, the input is returned invisibly.

Author(s)

Thomas Neitmann

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
library(admiral.test)
data(dm)

example_fun <- function(dataset) {
  assert_data_frame(dataset, required_vars = vars(STUDYID, USUBJID))
}

example_fun(dm)

try(example_fun(dplyr::select(dm, -STUDYID)))

try(example_fun("Not a dataset"))

epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.