Feather 为数据框提供二进制列式序列化。它的设计目的是使数据框的读取和写入效率更高,并使跨数据分析语言共享数据更容易。read_feather()
可以读取 Feather Version 1 (V1)(从 2016 年开始提供的旧版本)和 Version 2 (V2)(即 Apache Arrow IPC 文件格式)。read_ipc_file()
是 read_feather()
的别名。
用法
read_feather(file, col_select = NULL, as_data_frame = TRUE, mmap = TRUE)
read_ipc_file(file, col_select = NULL, as_data_frame = TRUE, mmap = TRUE)
参数
- file
字符型文件名或 URI、连接、
raw
向量、Arrow 输入流或带有路径 (SubTreeFileSystem
) 的FileSystem
。 如果是文件名或 URI,将会打开一个 Arrow InputStream,并在完成后关闭。 如果提供了输入流,它将被保持打开状态。- col_select
要保留的列名的字符向量,如
data.table::fread()
的 "select" 参数,或者 tidy selection specification 的列,如dplyr::select()
中使用。- as_data_frame
该函数应返回一个
tibble
(默认) 还是一个 Arrow Table?- mmap
逻辑值:是否对文件进行内存映射(默认
TRUE
)
值
如果 as_data_frame
为 TRUE
(默认),则返回一个 tibble
,否则返回一个 Arrow Table
参见
FeatherReader 和 RecordBatchReader 用于以较低级别访问读取 Arrow IPC 数据。
示例
# We recommend the ".arrow" extension for Arrow IPC files (Feather V2).
tf <- tempfile(fileext = ".arrow")
on.exit(unlink(tf))
write_feather(mtcars, tf)
df <- read_feather(tf)
dim(df)
#> [1] 32 11
# Can select columns
df <- read_feather(tf, col_select = starts_with("d"))