Skip to contents

Checks whether an object is a Date or can be safely coerced to a Date using base::as.Date(). If the input is coercible, it is returned invisibly; otherwise, an informative error is thrown.

Usage

ngr_chk_coerce_date(x, x_name = NULL)

Arguments

x

any An object expected to be a Date or a string coercible to a Date.

x_name

character Optional. A single string giving the name of x used in error messages. If NULL, the name is inferred from the calling expression.

Value

x invisibly if it is a Date or coercible to one. An error is thrown if coercion fails.

Details

This helper is intended for lightweight validation in functions that accept date inputs but do not need to modify them. Coercion is attempted via base::as.Date(), and failure results in a call to chk::abort_chk().