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)
util_expect_data_frame(
x,
col_names,
convert_if_possible,
custom_errors,
dont_assign,
keep_types = FALSE
)
invisible
data frame
an object that is verified to be a data.frame
.
column names x must contain or named list of predicates to check the columns (e.g., list(AGE=is.numeric, SEX=is.character))
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
list with error messages, specifically per column. names of the list are column names, values are messages (character).
set TRUE
to keep x
in the caller environment untouched
logical keep types as possibly defined in a file, if the
data frame is loaded from one. set TRUE
for
study data.