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 用于获取有关模式和元数据处理的信息。
示例
# 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)