check_dataframe_variable: Check if a data.frame contains variables

Description Usage Arguments Value Examples

Description

Check if a data.frame contains variables

Usage

1
2
check_dataframe_variable(df, variable, name = "df", force.NA = FALSE,
  error = TRUE)

Arguments

df

the data.frame to check

variable

either a character vector with the names of the variable to check or a named list. The names of the list must match the names of the required variables in the data.frame. The elements of the list contain the accepted classes for each varaible.

name

the name of the data.frame to use in the error message

force.NA

check the class of variables with all NA

error

When TRUE (default), the function returns an error when a variable is missing. Otherwise it returns a warning.

Value

The function returns TRUE when all variables are present. If returns FALSE when a variable is missing and error = FALSE.

Examples

1
2
3
4
5
6
7
8
check_dataframe_variable(
 df = data.frame(a = integer(0)),
 variable = "a"
)
check_dataframe_variable(
 df = data.frame(a = integer(0)),
 variable = list(a = c("integer", "numeric"))
)

inbo/n2khelper documentation built on May 18, 2019, 4:49 a.m.