Learn R Programming

DDIwR (version 0.24)

clearFormats: Clear statistical variable formats and widths

Description

Removes format or width metadata from a vector, or from every column of a data frame, across the supported statistical vendors.

Usage

clearFormats(x)

clearWidths(x)

Value

An object with the same values, class and structure as x, with the selected column metadata removed.

Arguments

x

An R vector or a data frame.

Details

clearFormats() removes format.spss, format.stata and format.sas, together with the format field in spss_metadata, stata_metadata and sas_metadata.

clearWidths() removes the existing width and display_width attributes, the width and display_width fields in spss_metadata, and the width fields in stata_metadata and sas_metadata. The existing width attribute is shared by the writers, including Stata string storage. Stata's type field is retained.

Both helpers remove matching list fields even when their value is NULL. Clearing the corresponding existing attributes at the same time prevents writer fallback from restoring a cleared format or width. Subsequent exports use the writer's defaults, including formats inferred from temporal classes and widths sufficient for string values.

Other metadata is retained, including labels, missing-value definitions, temporal classes and units, SAS informats, SPSS measurement and alignment, and custom attributes. A vendor list is removed when clearing its last field; otherwise its remaining fields, including unrelated NULL fields, are preserved. Existing empty lists are left unchanged.

For data frames, only column attributes are changed; dataset attributes are retained. List columns are treated as individual vectors without traversing their contents. Malformed vendor lists examined by the helper cause an error. Inputs are not modified; assign the returned object to keep the changes.

See Also

convert(), inspectFile()

Examples

Run this code
x <- structure(c(1, 2), format.spss = "F12.3", width = 8L)
attr(x, "spss_metadata") <- list(format = "F16.4", measure = "scale")
clearFormats(x)
clearWidths(x)

Run the code above in your browser using DataLab