You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Specifying column types with a named list inside cols() and cols_only() only works when the list is explicitly defined within cols() and cols_only(). Passing a named list created separately (e.g. loaded from a separate CSV of metadata) raises an error about collector objects.
mtcars_csv<- system.file("extdata", "mtcars.csv", package="readr")
# The named list of column types can be moved into a separate list, both with# column objects or abbreviations:col_types_list<- cols_only(
mpg= col_double(),
cyl= col_integer(),
disp= col_double(),
hp= col_integer()
)
col_types_list_abbr<- cols_only(
mpg="d",
cyl="i",
disp="d",
hp="i"
)
# And then it can be used in read_csv:df1<- read_csv(mtcars_csv, col_types=col_types_list)
df2<- read_csv(mtcars_csv, col_types=col_types_list_abbr)
# However, passing a named list object to cols() or cols_only() will not work,# raising an error about collector objects:col_list<-list(mpg= col_double(),
cyl= col_integer(),
disp= col_double(),
hp= col_integer())
col_list_abbr<-list(mpg="d",
cyl="i",
disp="d",
hp="i")
df3<- read_csv(mtcars_csv, col_types=cols_only(col_list))
#> Error: Some `col_types` are not S3 collector objects: 1df4<- read_csv(mtcars_csv, col_types=cols_only(col_list_abbr))
#> Error: Some `col_types` are not S3 collector objects: 1
I know it's a closed issue, but I got this "Error: Some col_types are not S3 collector objects: 1" error in a similar way. Is as_cols_only() in the readr library?
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/
Activity
hadley commentedon Jun 1, 2016
This implies we need
as_cols()andas_cols_only()antoine-lizee commentedon Jun 21, 2016
or something like a
.dotsargument tocols[_only]().andypohl commentedon Nov 2, 2017
I know it's a closed issue, but I got this "Error: Some
col_typesare not S3 collector objects: 1" error in a similar way. Isas_cols_only()in the readr library?hadley commentedon Nov 2, 2017
If you have a question, you're better off asking on community.rstudio.com
andypohl commentedon Nov 2, 2017
Thanks, I was pretty sure this wasn't the right place to ask.
lock commentedon Sep 25, 2018
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/