| read_spss | R Documentation |
Import an SPSS survey file in '.sav', '.zsav' or '.por' format with harmonized variable labels, value labels, missing value definitions and survey metadata.
read_spss(
file,
user_na = TRUE,
dataset_bibentry = NULL,
id = NULL,
doi = NULL,
.name_repair = "unique"
)
file |
Path to an SPSS survey file. |
user_na |
Logical. Preserve user-defined missing values and their definitions? Defaults to 'TRUE'. |
dataset_bibentry |
Optional bibliographic metadata created with [dataset::dublincore()] or [dataset::datacite()]. |
id |
Optional survey identifier. Defaults to the filename without its extension. |
doi |
Optional DOI identifier for the survey. |
.name_repair |
Column name repair strategy passed to [haven::read_spss()]. |
This function wraps [haven::read_spss()] and adds survey-specific observation identifiers, harmonized labelled vectors and provenance metadata.
Variables with value labels or user-defined missing value definitions are converted to 'labelled_spss_survey' vectors.
User-defined missing codes and missing ranges are preserved when 'user_na = TRUE', even when the source variable has no value labels.
When 'user_na = FALSE', user-defined missing values are converted to ordinary 'NA' values by haven.
Labelled numeric or character variables without value labels or missing value definitions are converted to ordinary vectors.
Variable labels and original column order are preserved. A 'rowid' column is added as the first variable, with observation identifiers prefixed by the survey identifier.
If an existing file cannot be imported by haven, an empty survey is returned with a warning. Nonexistent files raise an error.
A [survey_df()] object with survey metadata, labelled variables and provenance attributes.
Additional attributes include:
- 'id': survey identifier. - 'doi': DOI identifier, when available. - 'filename': original source filename. - 'object_size': size of the imported data in bytes. - 'source_file_size': size of the source file in bytes.
An unreadable file returns an empty [survey()] object.
[read_surveys()], [read_dta()], [read_rds()], [labelled_spss_survey()]
Other import functions:
harmonize_survey_variables(),
pull_survey(),
read_csv(),
read_dta(),
read_rds(),
read_surveys()
path <- system.file(
"examples",
"iris1.sav",
package = "retroharmonize"
)
survey_object <- read_spss(path)
attr(survey_object, "id")
attr(survey_object, "filename")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.