read_surveys: Read survey files into memory or save as '.rds'

View source: R/read_surveys.R

read_surveysR Documentation

Read survey files into memory or save as '.rds'

Description

Import one or more survey files into R using a consistent survey import workflow. The function supports SPSS ('.sav', '.por'), Stata ('.dta'), R ('.rds'), and CSV files.

Usage

read_surveys(
  survey_paths,
  .f = NULL,
  export_path = NULL,
  ids = NULL,
  dois = NULL,
  ...
)

read_survey(
  file_path,
  .f = NULL,
  export_path = NULL,
  doi = NULL,
  id = NULL,
  ...
)

Arguments

survey_paths

A character vector containing full or relative paths to survey files.

.f

Import function to use. When 'NULL', the appropriate import function is selected automatically from the file extension.

Supported formats are:

'.sav', '.por'

[read_spss()]

'.dta'

[read_dta()]

'.rds'

[read_rds()]

'.csv'

[read_csv()]

export_path

Optional path where imported surveys should be saved as '.rds' files. Defaults to 'NULL'.

ids

Optional survey identifiers.

dois

Optional DOI identifiers for the imported surveys.

...

Additional arguments passed to the import function.

Details

Use [read_survey()] to import a single survey file and 'read_surveys()' to import multiple files in a loop.

When 'export_path' is 'NULL', imported surveys are returned as a list in memory. When 'export_path' is a valid directory, imported surveys are saved as '.rds' files with [base::saveRDS()].

Files that cannot be imported are skipped gracefully. A message is printed and 'NULL' is returned for the affected file.

Value

If 'export_path = NULL', a list of imported survey objects.

If 'export_path' is provided, a character vector containing exported '.rds' file names.

Imported surveys are returned as data frame-like [survey()] objects with metadata attributes retained for reproducible workflows.

See Also

[read_survey()], [survey()]

Other import functions: harmonize_survey_variables(), pull_survey(), read_csv(), read_dta(), read_rds(), read_spss()

Examples

file1 <- system.file(
  "examples",
  "ZA7576.rds",
  package = "retroharmonize"
)

file2 <- system.file(
  "examples",
  "ZA5913.rds",
  package = "retroharmonize"
)

surveys <- read_surveys(
  c(file1, file2),
  .f = "read_rds"
)


retroharmonize documentation built on May 21, 2026, 9:06 a.m.