将命名列表传递给cols_only() [英] passing named list to cols_only()

查看:72
本文介绍了将命名列表传递给cols_only()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试做这样的事情时:

When I try to do something like this:

data <- read_csv("blah.csv",
+                n_max = 100,
+                col_types = cols_only(list(files = "c"))
+ )
Error: Some `col_types` are not S3 collector objects: 1

所以问题是是否可以将命名列表传递给cols_only()

so question is whether it is possible to pass a named list to cols_only()

推荐答案

当然,只需使用do.call将该列表用作该函数的参数即可,例如

Sure, just use do.call to use the list as the parameters for the function, e.g.

library(readr)

read_csv(system.file('extdata', 'mtcars.csv', package = 'readr'),    # sample data from readr
         col_types = do.call(cols_only, list(cyl = 'i')))

#> # A tibble: 32 × 1
#>      cyl
#>    <int>
#> 1      6
#> 2      6
#> 3      4
#> 4      6
#> 5      8
#> 6      6
#> 7      8
#> 8      4
#> 9      4
#> 10     6
#> # ... with 22 more rows

这篇关于将命名列表传递给cols_only()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆