Data frame failures¶
Source: R/errors.R ยท Help: ?data_frame_errors
Errors about the shape of a data frame: a required column that is absent, a
column of the wrong type, and a join whose keys do not line up. All three
inherit from dataexcept_data_frame_error, so one handler can catch the
family.
Usage¶
missing_column_error(column, dataframe = NULL, parent = NULL, call = NULL)
dtype_mismatch_error(column, expected, found, parent = NULL, call = NULL)
merge_key_error(left_keys, right_keys, parent = NULL, call = NULL)
Arguments¶
column- Name of the column.
dataframe- Optional name of the data frame, for the message.
parent- The condition that caused this one, or
NULL. call- The call to report, or
NULL. expected- Character vector of acceptable types, such as
c("numeric", "integer"). found- The type actually found, typically
class(x)[1]. left_keys,right_keys- Character vectors of join keys.
Value¶
A condition inheriting from dataexcept_data_frame_error.
Examples¶
orders <- data.frame(id = 1:3, amount = c("10", "20", "30"))
require_numeric <- function(df, column) {
if (!column %in% names(df)) {
stop(missing_column_error(column, dataframe = "orders"))
}
if (!is.numeric(df[[column]])) {
stop(dtype_mismatch_error(column, "numeric", class(df[[column]])[1]))
}
invisible(df)
}
tryCatch(
require_numeric(orders, "amount"),
dataexcept_data_frame_error = function(e) conditionMessage(e)
)
See also¶
Other dataexcept errors:
data_engineering_errors,
data_quality_errors,
file_errors,
job_errors,
model_quality_errors,
modelling_errors,
pipeline_errors,
service_errors,
validation_error()