tidyverse / readr

Read flat files (csv, tsv, fwf) into R
https://readr.tidyverse.org
Other
1.01k stars 286 forks source link

Use cols or list in read_csv #1515

Open Sibojang9 opened 1 year ago

Sibojang9 commented 1 year ago

The listand cols arguments in read_csvseem to be interchangeable, and I cannot find a clear answer online. Any insight into this?

library(tidyverse)

read_csv(
  "a,b,c
  4,5,6"
,col_types = list(a = col_factor()))
#> # A tibble: 1 × 3
#>   a         b     c
#>   <fct> <dbl> <dbl>
#> 1 4         5     6

read_csv(
  "a,b,c
  4,5,6"
  ,  col_types = cols(a = col_factor()))
#> # A tibble: 1 × 3
#>   a         b     c
#>   <fct> <dbl> <dbl>
#> 1 4         5     6

Created on 2023-09-06 with reprex v2.0.2

jxu commented 11 months ago

Documentation for cols says they're generally interchangable.

1392 related?