我一直在玩readr的read_delim_chunked
功能。根据{{3}},我们不清楚如何将参数传递给回调函数,或者是否可行。例如,从文档示例:
# Cars with 3 gears
f <- function(x, pos) {
dplyr::filter(x, .data[["gear"]] == 3)
}
readr::read_csv_chunked(
readr::readr_example("mtcars.csv"),
readr::DataFrameCallback$new(f),
chunk_size = 5)
# A tibble: 15 x 11
mpg cyl disp hp drat wt qsec vs am gear carb
<dbl> <int> <int> <int> <dbl> <dbl> <dbl> <int> <int> <int> <int>
1 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
2 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
3 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
这很好用。但是,如果我想参数化齿轮值呢?例如,
f <- function(x, pos, gear_val) {
dplyr::filter(x, .data[["gear"]] == gear_val)
}
readr::read_csv_chunked(
readr::readr_example("mtcars.csv"),
readr::DataFrameCallback$new(f, gear_val = 3),
chunk_size = 5
)
Error in .subset2(public_bind_env, "initialize")(...) :
unused argument (gear_val = 3)
我尝试过尝试将参数传递给回调函数的各种组合,但它不起作用。有没有人对如何做到这一点有任何想法?