
Read Excel Data With Multi-Row Column Headers
Source:R/read_excel_multiple_headers.R
read_excel_multiple_headers.RdVariant of read_excel for sheets where column names
are split across multiple header rows. The rows are concatenated in order,
joined with sep. Supports hierarchical/merged headers via horizontal
forward-filling across upper header tiers, isolates text parsing for headers
so data col_types do not collide, and performs robust name repair.
Usage
read_excel_multiple_headers(
path,
n_header_rows = 2L,
sheet = 1,
fill_merged = FALSE,
sep = " | ",
clean_names = FALSE,
trim = TRUE,
...
)Arguments
- path
Path to the
.xls/.xlsxfile.- n_header_rows
Number of header rows in the sheet (positive integer >= 1).
- sheet
Sheet to read. Either a string (the name of a sheet), or an integer (the position of the sheet). Defaults to
1.- fill_merged
Logical (default
FALSE); ifTRUE, handles merged cells in upper header rows by forward-filling non-empty values left-to-right across columns before vertical concatenation.- sep
Character string used to separate header levels. Default
" | ".- clean_names
Logical (default
FALSE); ifTRUE, appliesclean_names_keep_labelsto sanitize the final column names.- trim
Logical (default
TRUE); whether to trim leading/trailing whitespace from header cells.- ...
Additional arguments passed to
read_excelfor reading the data body (e.g.col_types,na,guess_max).