read_csv: Read a survey dataset from a CSV file

View source: R/read_csv.R

read_csvR Documentation

Read a survey dataset from a CSV file

Description

Import survey data from a comma-separated values (CSV) file into a survey data frame with reproducibility metadata.

Usage

read_csv(file, id = NULL, doi = NULL, dataset_bibentry = NULL, ...)

Arguments

file

Path to a CSV file.

id

Optional survey identifier. If omitted, the file path without its extension is used.

doi

Optional digital object identifier (DOI). If omitted, the first value of the 'doi' column is used, when available.

dataset_bibentry

Optional bibliographic metadata created with [dataset::dublincore()] or [dataset::datacite()].

...

Reserved for additional import arguments. Currently unused.

Details

The CSV file must contain a 'rowid' column identifying the observations. Character variables may be converted into defined categorical variables.

If the file cannot be parsed, a warning is issued and an empty survey object is returned.

Value

A 'survey_df' object with survey identifiers, bibliographic metadata, source filename, object size, and source file size. An empty 'survey' object is returned if the file cannot be parsed.

See Also

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

Examples

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

example_survey <- read_rds(path)
csv_file <- tempfile(fileext = ".csv")

utils::write.csv(
  x = example_survey,
  file = csv_file,
  row.names = FALSE
)

imported_survey <- read_csv(
  file = csv_file,
  id = "ZA7576"
)

unlink(csv_file)

retroharmonize documentation built on Nov. 29, 2026, 5:06 p.m.