Feather 为数据帧提供二进制列式序列化。它旨在使数据帧的读写高效,并使跨数据分析语言共享数据变得容易。write_feather() 可以写入 Feather 版本 1 (V1)(一个自 2016 年开始提供的旧版本)和版本 2 (V2)(即 Apache Arrow IPC 文件格式)。默认版本是 V2。V1 文件与 Arrow IPC 文件不同,并且缺少许多功能,例如存储所有 Arrow 数据类型和支持压缩的能力。write_ipc_file() 只能写入 V2 文件。
用法
write_feather(
x,
sink,
version = 2,
chunk_size = 65536L,
compression = c("default", "lz4", "lz4_frame", "uncompressed", "zstd"),
compression_level = NULL
)
write_ipc_file(
x,
sink,
chunk_size = 65536L,
compression = c("default", "lz4", "lz4_frame", "uncompressed", "zstd"),
compression_level = NULL
)参数
- x
data.frame、RecordBatch 或 Table- sink
字符串文件路径、连接、URI 或 OutputStream,或文件系统中的路径 (
SubTreeFileSystem)- version
整数 Feather 文件版本,版本 1 或版本 2。版本 2 是默认值。
- chunk_size
对于 V2 文件,文件中每个数据块应包含的行数。当您需要更快的随机行访问时,请使用较小的
chunk_size。默认值为 64K。此选项不适用于 V1。- compression
要使用的压缩编解码器名称(如果有)。如果您的 Arrow C++ 库构建中支持 LZ4,则默认为“lz4”,否则为“uncompressed”。“zstd”是另一个可用的编解码器,通常具有更好的压缩比,但读写性能较慢。“lz4”是“lz4_frame”编解码器的简写。有关详细信息,请参阅
codec_is_available()。TRUE和FALSE也可以代替“default”和“uncompressed”使用。此选项不适用于 V1。- compression_level
如果
compression为“zstd”,您可以指定一个整数压缩级别。如果省略,则使用压缩编解码器的默认压缩级别。
返回值
输入 x,不可见。请注意,如果 sink 是 OutputStream,则流将保持打开状态。
另请参阅
RecordBatchWriter 用于对写入 Arrow IPC 数据进行较低级别的访问。
Schema 用于获取有关 schema 和元数据处理的信息。
示例
# We recommend the ".arrow" extension for Arrow IPC files (Feather V2).
tf1 <- tempfile(fileext = ".feather")
tf2 <- tempfile(fileext = ".arrow")
tf3 <- tempfile(fileext = ".arrow")
on.exit({
unlink(tf1)
unlink(tf2)
unlink(tf3)
})
write_feather(mtcars, tf1, version = 1)
write_feather(mtcars, tf2)
write_ipc_file(mtcars, tf3)