Feather 为数据框提供了二进制列式序列化功能。它旨在提高数据框读写的效率,并使跨数据分析语言共享数据变得容易。read_feather() 可以读取 Feather 第 1 版(V1,2016 年推出的旧版本)和第 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 输入流,或带有路径的FileSystem(SubTreeFileSystem)。如果是文件名或 URI,将打开一个 Arrow InputStream 并在完成后关闭。如果提供了输入流,它将保持打开状态。- col_select
要保留的列名的字符向量,类似于
data.table::fread()中的 "select" 参数,或 tidy selection 规范的列,如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"))