Writes a data frame to a Parquet file. When encryption_key is
supplied the file is encrypted with AES using DuckDB's native Parquet
encryption support. Without a key the file is written by
arrow::write_parquet() and supports any compression codec
understood by the Arrow library.
Arguments
- data
A data frame or tibble to write.
- path
Character string. Destination file path for the Parquet file.
- ...
Additional arguments passed to
arrow::write_parquet()whenencryption_keyisNULL.- encryption_key
A raw AES key as a hex string (32, 48, or 64 hex characters) or a base-64–encoded 256-bit key string. When
NULL(default) no encryption is applied.- conn
An optional existing DuckDB
DBIConnection. When supplied, the connection is reused instead of opening a new one, which avoids per-call setup overhead when writing many tables in a batch. The caller is responsible for disconnecting the connection. Default isNULL.- compression
Compression codec to use for unencrypted Parquet files. Any codec supported by
arrow::write_parquet()is valid (e.g."zstd","snappy","gzip","lz4","uncompressed"). Ignored whenencryption_keyis set (DuckDB chooses the codec). Default is"zstd".
Examples
if (FALSE) { # \dontrun{
data <- mtcars
key <- "rppqM5CuEqotys4wQq/g7xh6wpIjRozcAIbI9sagwKE="
temp_dir <- tempdir()
# Encrypted write
rcdf::write_parquet(
data = data,
path = file.path(temp_dir, "mtcars.parquet"),
encryption_key = key
)
# Unencrypted write with gzip compression
rcdf::write_parquet(
data = data,
path = file.path(temp_dir, "mtcars-gz.parquet"),
compression = "gzip"
)
} # }