※ 引述《locka (locka)》之铭言:
: library(tidyverse)
: library(readr)
: # 产生测试资料
: demo <- tibble(variable=1:16,
: id1=rnorm(16),
: id2=rnorm(16),
: id3=rnorm(16),
: id4=rnorm(16))
: write_csv(demo, "demo.csv")
: # 使用read_csv_chunked() 每4row切割并输出成一个新的档案
: callback_f <- function(x, pos) write_csv(x, paste0("chunk_",pos%/%4,".csv"))
: read_csv_chunked("demo.csv", DataFrameCallback$new(callback_f), chunk_size=4
)
: 结果如下:
: 原资料
: https://i.imgur.com/y3GmbSh.jpg
: 输出4个档案
: https://i.imgur.com/5b2pzEi.jpg