read_source: Read a source table (xlsx or csv) as raw character data

View source: R/read_source.r

read_sourceR Documentation

Read a source table (xlsx or csv) as raw character data

Description

The first row is always taken as the header. Excel formulas are read as their cached values; cell formatting (colours, merged cells, number formats) is not read. CSV files are read with an auto-detected delimiter (comma, semicolon, tab or pipe) and encoding (Hungarian Excel exports are often semicolon-separated windows-1250).

Usage

read_source(
  path,
  sheet = NULL,
  guess_max = 1e+05,
  delim = NULL,
  encoding = NULL
)

Arguments

path

Path to an .xlsx/.xlsm/.xls or .csv/.txt file.

sheet

Sheet name or index for Excel files (default: first sheet).

guess_max

Rows used by readxl to guess the original column types, which are only used to restore cell types on writing.

delim, encoding

CSV only; NULL detects them.

Value

A synth_source list: raw (data.frame of character, internal unique names), orig_names (header as on disk, duplicates allowed), orig_class (readxl/readr guessed class per column), path, sheet, format, and for CSV delim and encoding.

Examples

df <- data.frame(id = sprintf("AB%03d", 1:60), value = 1:60,
                 code = rep(c(0, 1, NA), 20))
path <- file.path(tempdir(), "read_source.csv")
utils::write.csv(df, path, row.names = FALSE, na = "")
src <- read_source(path)
head(src$raw)

cellsynth documentation built on Oct. 31, 2026, 1:07 a.m.