check_dataframe_variable: Check if a data.frame contains variables

View source: R/check_dataframe_variable.R

check_dataframe_variableR Documentation

Check if a data.frame contains variables

Description

Check if a data.frame contains variables

Usage

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

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-Natura2000/n2khelper documentation built on April 5, 2022, 5:40 p.m.