import_xlsx | R Documentation |
XLSX
Files with Advanced HandlingA robust and flexible function for importing data from one or multiple
XLSX
files, offering comprehensive options for sheet selection,
data combination, and source tracking.
import_xlsx(file, rbind = TRUE, sheet = NULL, ...)
file |
A |
rbind |
A
|
sheet |
A
|
... |
Additional arguments passed to |
The function provides a comprehensive solution for importing Excel data with the following features:
Supports multiple files and sheets
Automatic source tracking for files and sheets
Flexible combining options
Handles missing columns across sheets when combining
Preserves original data types through readxl
Depends on the rbind
parameter:
If rbind = TRUE
: A single data.table
with additional tracking columns:
- excel_name
: Source file name (without extension)
- sheet_name
: Source sheet name
If rbind = FALSE
: A named list of data.table
s with format
"filename_sheetname"
Critical Import Considerations:
Requires all specified files to be accessible Excel
files
Sheet indices must be valid across input files
rbind = TRUE
assumes compatible data structures
Missing columns are automatically filled with NA
File extensions are automatically removed in tracking columns
readxl::read_excel()
for underlying Excel reading
data.table::rbindlist()
for data combination
# Example: Excel file import demonstrations
# Setup test files
xlsx_files <- mintyr_example(
mintyr_examples("xlsx_test") # Get example Excel files
)
# Example 1: Import and combine all sheets from all files
import_xlsx(
xlsx_files, # Input Excel file paths
rbind = TRUE # Combine all sheets into one data.table
)
# Example 2: Import specific sheets separately
import_xlsx(
xlsx_files, # Input Excel file paths
rbind = FALSE, # Keep sheets as separate data.tables
sheet = 2 # Only import first sheet
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.