as.Date.haven_labelled_defined: Coerce a defined Date vector to a base R Date

View source: R/as.Date.R

as.Date.haven_labelled_definedR Documentation

Coerce a defined Date vector to a base R Date

Description

Coerces a haven_labelled_defined vector whose underlying type is Date into a base R Date vector.

This method preserves the underlying date values and, by default, also retains any semantic metadata attached to the variable.

Usage

## S3 method for class 'haven_labelled_defined'
as.Date(x, strip_attributes = FALSE, ...)

Arguments

x

A vector created with defined() with underlying type Date.

strip_attributes

Logical; should the semantic metadata attributes (label, unit, definition, namespace) be removed from the returned vector? Defaults to FALSE.

...

Additional arguments passed to base::as.Date().

Details

Use strip_attributes = TRUE when flattening or preparing data for external pipelines, but keep the default when working with defined vectors directly.

Base R's as.Date() also works, as it dispatches to this method via S3. However, using as.Date() on defined vectors is considered safe because this method ensures metadata is handled predictably.

Value

A Date vector, optionally carrying semantic metadata.

See Also

as.POSIXct(), as_numeric(), as_character(), as_logical(), defined()

Examples

d <- defined(Sys.Date() + 0:2, label = "Observation date")

# Recommended usage
as.Date(d)

# Stripping metadata
as.Date(d, strip_attributes = TRUE)


dataset documentation built on Nov. 16, 2025, 5:06 p.m.