| import_csv | R Documentation |
Reads one or more CSV/TXT files using fread as the backend.
Supports flexible combination strategies and source-file tracking. All return values
are data.table objects.
import_csv(
file,
combine = TRUE,
file_col = "_file",
full_path = FALSE,
keep_ext = FALSE,
...
)
file |
A non-empty |
combine |
A
|
file_col |
A |
full_path |
A
|
keep_ext |
A
|
... |
Additional arguments passed directly to |
Label generation is controlled by the combination of full_path and keep_ext:
full_path = FALSE, keep_ext = FALSE | Filename without extension: "data" |
full_path = FALSE, keep_ext = TRUE | Filename with extension: "data.csv" |
full_path = TRUE, keep_ext = FALSE | Full path without extension: "/path/to/data" |
full_path = TRUE, keep_ext = TRUE | Full path with extension: "/path/to/data.csv" |
When combine = TRUE and file_col is not NULL,
rbindlist is called with idcol = file_col,
which generates the source column directly during the merge step without any
intermediate copies.
combine = TRUE: A single data.table containing all imported rows.
If file_col is not NULL, the first column contains the source
file label for each row.
combine = FALSE: A named list of data.table objects.
List names are derived from file paths according to full_path and
keep_ext settings.
All specified files must exist and be readable at call time.
combine = TRUE assumes compatible column structures across files;
mismatched columns are automatically aligned via fill = TRUE.
Logical parameters (combine, full_path, keep_ext) reject
NA values explicitly.
Only the extension of the file itself is stripped; dots in directory
names (e.g. "v1.2/file") are left intact.
Duplicated labels (same file name in different folders) trigger a
warning and are made unique with make.unique().
fread, rbindlist
# Example: CSV file import demonstrations
# Setup test files
csv_files <- mintyr_example(
mintyr_examples("csv_test") # Get example CSV files
)
# Example 1: Import and combine CSV files using data.table
import_csv(
csv_files, # Input CSV file paths
combine = TRUE, # Combine all files into one data.table
file_col = "_file", # Column name for file source
keep_ext = TRUE, # Include .csv extension in _file column
full_path = TRUE # Show complete file paths in _file column
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.