read_readstat_metadata() reads what a file says about its data (variable
labels, display formats, value labels, user-defined missing values) without
reading the data itself.
Usage
read_readstat_metadata(
path,
format = NULL,
catalog_file = NULL,
encoding = NULL
)
read_dta_metadata(path, ...)
read_sas_metadata(path, ...)
read_xpt_metadata(path, ...)
read_sav_metadata(path, ...)
read_por_metadata(path, ...)
read_stata_metadata(path, ...)
read_spss_metadata(path, ...)Arguments
- path
Path to the file.
- format
One of
"sas","xpt","stata","spss"(.sav,.zsav) or"por"(SPSS portable).NULL(default) detects it from the extension.- catalog_file
Only for SAS files. Path to a SAS format catalog (
.sas7bcat) holding the value labels of a SAS data file, orNULL(default). With it,value_labelslists the labels of the columns whose display format the catalog defines.- encoding
Only for Stata files. The text encoding of a Stata file, or
NULL(default), as forread_readstat().- ...
Passed on to
read_readstat_metadata().
Value
A readstat_metadata object: a list with
format: the file format, as for theformatargument.n_rows: the number of rowsread_readstat()returns (for SAS, rows marked as deleted aren't counted), orNAif the file doesn't record it (SAS transport and SPSS portable files). For SPSS files whose header doesn't record it, the rows are counted, which reads the whole file.label: the label of the whole dataset, orNA.encoding: the character encoding the file's text is read in (for Stata,encodingor the format's default), orNAif unknown (SAS transport and SPSS portable files).variables: a data frame with one row per variable, named after it:name,label, displayformat,type("numeric"or"character"), and for SPSSmeasure,display_widthandalignment. Values a file doesn't have areNA.value_labels: a named list with an element per variable that has value labels: its labelled values, named by their labels, like the"labels"attribute of haven. Values are numbers for numeric variables and strings for character ones.missing_labels: a named list with an element per Stata or SAS variable whose missing values have labels: their codes (".", and".a"to".z"in Stata,".A"to".Z"and"._"in SAS), named by their labels. haven keeps these in"labels"too, on taggedNAs.na_values,na_range: named lists with an element per SPSS variable that has user-defined missing values: its discrete missing values, and its missing range asc(low, high)(-InfandInfforLOandHI), like the attributes of the same names in haven.
Details
read_readstat_metadata() will detect the format from the file extension,
while read_dta_metadata(), read_sas_metadata(), read_xpt_metadata(),
read_sav_metadata() and read_por_metadata() read the specified format.
Examples
path <- system.file("examples", "iris.sav", package = "haven")
if (nzchar(path)) {
meta <- read_readstat_metadata(path)
meta
meta$variables["Species", "label"]
meta$value_labels$Species
}
#> setosa versicolor virginica
#> 1 2 3