The export_list
function exports a list of data.frame
, data.table
, or compatible data structures
with sophisticated directory handling, flexible naming, and multiple file format support.
export_list(split_dt, export_path = tempdir(), file_type = "txt")
A list
of data.frame
, data.table
, or compatible data structures
to be exported.
Base directory path for file export. Defaults to a temporary directory
created by tempdir()
.
File export format, either "txt"
(tab-separated) or "csv"
.
Defaults to "txt"
.
An integer
representing the total number of files exported successfully.
Comprehensive List Export Features:
Advanced nested directory structure support based on list element names
Intelligent handling of unnamed list elements
Automatic conversion to data.table
for consistent export
Hierarchical directory creation with nested path names
Multi-format file export with intelligent separator selection
Robust error handling and input validation
File Export Capabilities:
Supports "txt"
(tab-separated) and "csv"
formats
Intelligent file naming based on list element names
Handles complex nested directory structures
Efficient file writing using data.table::fwrite()
Key Capabilities:
Flexible list naming and directory management
Comprehensive support for data.frame
and data.table
inputs
Intelligent default naming for unnamed elements
High-performance file writing mechanism
# Example: Export split data to files
# Step 1: Create split data structure
dt_split <- w2l_split(
data = iris, # Input iris dataset
cols2l = 1:2, # Columns to be split
by = "Species" # Grouping variable
)
# Step 2: Export split data to files
export_list(
split_dt = dt_split # Input list of data.tables
)
#> [1] 6
# Returns the number of files created
# Files are saved in tempdir() with .txt extension
# Check exported files
list.files(
path = tempdir(), # Default export directory
pattern = "txt", # File type pattern to search
recursive = TRUE # Search in subdirectories
)
#> [1] "Sepal.Length_setosa.txt" "Sepal.Length_versicolor.txt"
#> [3] "Sepal.Length_virginica.txt" "Sepal.Width_setosa.txt"
#> [5] "Sepal.Width_versicolor.txt" "Sepal.Width_virginica.txt"
# Clean up exported files
files <- list.files(
path = tempdir(), # Default export directory
pattern = "txt", # File type pattern to search
recursive = TRUE, # Search in subdirectories
full.names = TRUE # Return full file paths
)
file.remove(files) # Remove all exported files
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE