| Title: | Read xlsx Files with a Native Parser |
|---|---|
| Description: | Reads tabular data from xlsx files with a specialized C parser. Worksheet XML is scanned in a single pass and decoded directly into R vectors, with no intermediate document model. Bundles the 'miniz' and 'libdeflate' decompressors to read the underlying archive. |
| Authors: | Vincent Shields [aut, cre, cph], Rich Geldreich [ctb, cph] (author of the bundled miniz), Tenacious Software LLC [cph] (copyright holder of the bundled miniz), RAD Game Tools and Valve Software [cph] (copyright holder of the bundled miniz), Martin Raiber [ctb, cph] (contributor to and copyright holder of the miniz ZIP reader), Alex Evans [ctb] (author of the PNG writer in the bundled miniz), Alistair Moffat [ctb] (author of the minimum-redundancy code in the bundled miniz), Jyrki Katajainen [ctb] (author of the minimum-redundancy code in the bundled miniz), Eric Biggers [ctb, cph] (author of the bundled libdeflate), Google LLC [cph] (copyright holder of the bundled libdeflate) |
| Maintainer: | Vincent Shields <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-10-08 02:12:57 UTC |
| Source: | https://github.com/vlshields/rcxl |
Reads one worksheet from an xlsx file into a data frame. Column types are
guessed from the cells unless overridden with col_types.
read_xlsx( path, sheet = 1L, col_names = TRUE, trim_ws = TRUE, range = NULL, skip = 0L, n_max = Inf, col_types = NULL, na = "", name_repair = c("unique", "minimal", "check_unique") )read_xlsx( path, sheet = 1L, col_names = TRUE, trim_ws = TRUE, range = NULL, skip = 0L, n_max = Inf, col_types = NULL, na = "", name_repair = c("unique", "minimal", "check_unique") )
path |
Path to an xlsx file. Tilde expansion is applied. |
sheet |
Worksheet to read, as a 1-based index or a sheet name.
Overridden when |
col_names |
|
trim_ws |
Trim leading and trailing whitespace from string cells and column names? |
range |
A1-style cell range to read: |
skip |
Number of rows to skip before reading anything. Ignored when
|
n_max |
Maximum number of data rows to read. The column name row
does not count. Ignored when |
col_types |
|
na |
Character vector of strings to read as |
name_repair |
How to resolve column names in the result. |
A guessed column becomes character if it holds any string cell, logical if
it holds only booleans, POSIXct if it holds date cells and no plain
numbers, and numeric otherwise. Every cell in the read area informs the
guess. Columns with only blank cells become logical NA. Date cells are returned as POSIXct in UTC; both the 1900
and 1904 date systems are handled, including the nonexistent 29 Feb 1900
that the 1900 system counts.
Cells that cannot be coerced to a type forced through col_types become
NA, with a warning giving the count and the first offending cell.
A data.frame with one column per worksheet column read.
read_xlsx_all() to read several sheets in one workbook pass;
xlsx_sheets() for the sheet names.
types <- system.file("extdata", "types.xlsx", package = "rcxl") str(read_xlsx(types)) # read a rectangle rather than the whole sheet read_xlsx(types, range = "A1:C3") # force every column to character instead of guessing str(read_xlsx(types, col_types = "text")) # a sheet other than the first, by name or by position multi <- system.file("extdata", "multisheet.xlsx", package = "rcxl") read_xlsx(multi, sheet = "Beta")types <- system.file("extdata", "types.xlsx", package = "rcxl") str(read_xlsx(types)) # read a rectangle rather than the whole sheet read_xlsx(types, range = "A1:C3") # force every column to character instead of guessing str(read_xlsx(types, col_types = "text")) # a sheet other than the first, by name or by position multi <- system.file("extdata", "multisheet.xlsx", package = "rcxl") read_xlsx(multi, sheet = "Beta")
Reads multiple sheets from an xlsx file through one shared workbook pass,
so the ZIP directory, shared strings and styles are parsed once. All
arguments other than sheets apply to every sheet read.
read_xlsx_all( path, sheets = NULL, col_names = TRUE, trim_ws = TRUE, range = NULL, skip = 0L, n_max = Inf, col_types = NULL, na = "", name_repair = c("unique", "minimal", "check_unique") )read_xlsx_all( path, sheets = NULL, col_names = TRUE, trim_ws = TRUE, range = NULL, skip = 0L, n_max = Inf, col_types = NULL, na = "", name_repair = c("unique", "minimal", "check_unique") )
path |
Path to an xlsx file. Tilde expansion is applied. |
sheets |
Sheets to read, as a vector of 1-based indices or sheet
names. |
col_names |
|
trim_ws |
Trim leading and trailing whitespace from string cells and column names? |
range |
As in |
skip |
Number of rows to skip before reading anything. Ignored when
|
n_max |
Maximum number of data rows to read. The column name row
does not count. Ignored when |
col_types |
|
na |
Character vector of strings to read as |
name_repair |
As in |
A named list of data.frames, one per sheet read, named by sheet
name.
multi <- system.file("extdata", "multisheet.xlsx", package = "rcxl") sheets <- read_xlsx_all(multi) names(sheets) sheets[["Alpha"]] # a subset of the sheets, still in one workbook pass names(read_xlsx_all(multi, sheets = c("Alpha", "Gamma")))multi <- system.file("extdata", "multisheet.xlsx", package = "rcxl") sheets <- read_xlsx_all(multi) names(sheets) sheets[["Alpha"]] # a subset of the sheets, still in one workbook pass names(read_xlsx_all(multi, sheets = c("Alpha", "Gamma")))
List worksheet names
xlsx_sheets(path)xlsx_sheets(path)
path |
Path to an xlsx file. Tilde expansion is applied. |
A character vector of sheet names in workbook order.
xlsx_sheets(system.file("extdata", "multisheet.xlsx", package = "rcxl"))xlsx_sheets(system.file("extdata", "multisheet.xlsx", package = "rcxl"))