Learn R Programming

DDIwR (version 0.24)

inspectFile: Inspect statistical file metadata without importing observations

Description

Reads column definitions and dataset metadata from SPSS, Stata and SAS files without decoding observations or allocating vectors for data rows.

Usage

inspectFile(
  file,
  encoding = NULL,
  catalog_file = NULL,
  catalog_encoding = encoding
)

Value

A list with numeric row_count, integer column_count, a columns

data frame with name, type, width and metadata, and a named list of dataset metadata.

Arguments

file

One path to a supported statistical file.

encoding

One character encoding override, or NULL to use file metadata and the reader's fallback.

catalog_file

Optional path to a SAS format catalog, for .sas7bdat.

catalog_encoding

Optional catalog encoding override; defaults to encoding. Data and catalog overrides follow the same precedence as native SAS import.

Details

Supported extensions are .sav, .zsav, .por, .dta, .sas7bdat and .xpt. The file's original row count is returned when its metadata provides one, including zero for a known empty dataset. Unknown counts are NA_real_; observations are never scanned to calculate them. POR and XPT 5 do not store row counts. XPT 8 counts are returned when the observation header supplies one; blank or all-zero reserved fields mean unknown. SAS7BDAT counts exclude rows marked as deleted in the metadata.

Column definitions retain source order, ReadStat storage type and byte width. Types are "string", "int8", "int16", "int32", "float", "double" or "string_ref". A metadata list column holds each column's R attributes, including labels, missing definitions, formats, temporal classes, vendor metadata and custom attributes. Data-derived attributes such as missing-value row positions are unavailable. Dataset metadata uses the same attribute names as convert(), including label, spss_metadata, stata_metadata, sas_metadata, spss.attributes and stata.characteristics.

Metadata may occur after observations, so the reader can seek beyond data sections to obtain definitions such as Stata value labels. SAS metadata pages may also contain observation bytes; those pages are read as blocks, but observations are not decoded or decompressed. Inspection does not validate observation content. Supply catalog_file to include SAS value labels from a separate format catalog. No catalog is selected automatically.

Examples

Run this code
if (FALSE) {
info <- inspectFile("survey.sav")
info$row_count
info$columns
info$metadata$label
}

Run the code above in your browser using DataLab