Unified file writing block
write.RdA variadic block for writing dataframes to files in various formats. Accepts multiple input dataframes and handles single files, multi-sheet Excel, or ZIP archives depending on format and number of inputs.
Usage
new_write_block(
directory = "",
filename = "",
format = "csv",
mode = "download",
auto_write = TRUE,
args = list(),
...
)Arguments
- directory
Character. Default directory for file output (browse mode only). Can be configured via
options(blockr.write_dir = "/path")or environment variableBLOCKR_WRITE_DIR. Default: current working directory.- filename
Character. Optional fixed filename (without extension).
If provided: Writes to same file path on every upstream change (auto-overwrite)
If empty (default): Generates timestamped filename (e.g.,
data_20250127_143022.csv)
- format
Character. Output format: "csv", "excel", "parquet", or "feather". Default: "csv"
- mode
Character. Either "download" to trigger browser download (recommended for beginners), or "browse" to write files to server filesystem. Default: "download"
- auto_write
Logical. When TRUE (default), automatically writes files when data changes (browse mode only). When FALSE, user must click "Write File" button to save. Has no effect in download mode.
- args
Named list of format-specific writing parameters. Only specify values that differ from defaults. Available parameters:
For CSV files:
sep(default: ","),quote(default: TRUE),na(default: "")For Excel/Arrow: Minimal options needed (handled by underlying packages)
- ...
Forwarded to
blockr.core::new_transform_block()
Details
Variadic Inputs
This block accepts multiple dataframe inputs (1 or more) similar to bind_rows_block.
Inputs can be numbered ("1", "2", "3") or named ("sales_data", "inventory").
Input names are used for sheet names (Excel) or filenames (multi-file ZIP).
File Output Behavior
Single input:
Writes single file in specified format
Filename:
{filename}.{ext}ordata_{timestamp}.{ext}
Multiple inputs + Excel:
Single Excel file with multiple sheets
Sheet names derived from input names
Multiple inputs + CSV/Arrow:
Single ZIP file containing individual files
Each file named from input names
Filename Behavior
Fixed filename (filename = "output"):
Reproducible path: always writes to
{directory}/output.{ext}Overwrites file on every upstream data change
Ideal for automated pipelines
Auto-timestamped (filename = ""):
Unique files:
{directory}/data_YYYYMMDD_HHMMSS.{ext}Preserves history, prevents accidental overwrites
Safe default behavior
Examples
if (FALSE) { # \dontrun{
# Single dataframe to CSV
serve(new_write_block(
directory = "/tmp",
filename = "output",
format = "csv"
))
# Multiple dataframes to Excel with auto-timestamp
serve(new_write_block(
directory = "/tmp",
filename = "", # auto-generated
format = "excel"
))
# CSV with custom delimiter
serve(new_write_block(
directory = "/tmp",
filename = "data",
format = "csv",
args = list(sep = ";")
))
} # }