Learn R Programming

dataquieR (version 2.1.0)

util_expect_data_frame: Verify, that argument is a data frame

Description

stops with an error, if not. will add the columns, and return the resulting extended data frame, and also updating the original data frame in the calling environment, if #' x is empty (data frames easily break to 0-columns in R, if they have not rows, e.g. using some split/rbind pattern)

Usage

util_expect_data_frame(
  x,
  col_names,
  convert_if_possible,
  custom_errors,
  dont_assign,
  keep_types = FALSE
)

Value

invisible data frame

Arguments

x

an object that is verified to be a data.frame.

col_names

column names x must contain or named list of predicates to check the columns (e.g., list(AGE=is.numeric, SEX=is.character))

convert_if_possible

if given, for each column, a lambda can be given similar to col_names check functions. This lambda would be used to try a conversion. If a conversion fails (returns NA, where the input was not `util_empty'), an error is still thrown, the data is converted, otherwise

custom_errors

list with error messages, specifically per column. names of the list are column names, values are messages (character).

dont_assign

set TRUE to keep x in the caller environment untouched

keep_types

logical keep types as possibly defined in a file, if the data frame is loaded from one. set TRUE for study data.