Returns a securer::securer_tool() that writes data to files in
specified directories with size limits and overwrite protection.
Usage
tool_write_file(
allowed_dirs,
max_file_size = "10MB",
max_calls = NULL,
overwrite = FALSE
)
write_file_tool(...)Details
The content argument type is declared as "list" in the tool schema
because the IPC serialization layer (JSON) converts most R objects to
lists. In practice, callers should pass:
A
data.framefor CSV and JSON formatsA character vector for TXT format
Any R object for RDS format
Supported formats: csv, json, txt, rds. Format is auto-detected from the file extension, or can be specified explicitly.
Security constraints:
Atomic writes: Data is written to a temp file first, validated for size, then moved to the target path.
Overwrite protection: By default, existing files cannot be overwritten (controlled by the
overwriteparameter).Symlink resolution: Target paths are resolved via
base::normalizePath()to prevent symlink-based directory escapes.Size limits: Written files exceeding
max_file_sizeare rejected before being moved to the target.
See also
Other tool factories:
tool_calculator(),
tool_data_profile(),
tool_fetch_url(),
tool_plot(),
tool_query_sql(),
tool_r_help(),
tool_read_file()