Skip to contents

Converts x to target_type and checks whether the conversion introduced any new NA values (i.e. values that were non-missing before but became NA after casting). Returns a list so the caller can decide whether to apply the result or record an issue.

Usage

.coerce_column(x, target_type, var, dataset_label = "")

Arguments

x

A vector (one column from the data.table).

target_type

String: "integer", "numeric", "double", "character", or "logical".

var

Variable name (used in issue messages only).

dataset_label

Dataset label for warning messages.

Value

A list:

converted

The coerced vector, or NULL for unknown types.

success

TRUE if coercion is safe (no new NAs).

issue

A one-row data.table describing the problem, or NULL.

Details

Separating the attempt from the application means .coerce_all_columns() never modifies the table for a column that would silently lose data.