Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The id column should also be selectable in col_select() #110

Closed
jimhester opened this issue May 14, 2019 · 3 comments
Closed

The id column should also be selectable in col_select() #110

jimhester opened this issue May 14, 2019 · 3 comments
Labels
feature a feature request or enhancement tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day

Comments

@jimhester
Copy link
Collaborator

library(vroom)
vroom(vroom_example("mtcars.csv"), id = "path", col_select = list(path, everything()))
#> Error in vroom_(file, delim = delim, col_names = col_names, col_types = col_types, : Evaluation error: object 'path' not found.

Created on 2019-05-14 by the reprex package (v0.2.1)

@jimhester jimhester added the feature a feature request or enhancement label May 14, 2019
@jimhester jimhester added the tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day label Jul 1, 2019
@jimhester
Copy link
Collaborator Author

jimhester commented Jul 1, 2019

This is more advanced than other TDD issues, but if you are familiar with C or C++ should be fairly straightforward. The [id] argument needs to be passed to resolve_collectors and added to the column names used in col_types_standardise(). Come find me if you need help getting started.

@ahcyip
Copy link

ahcyip commented Mar 9, 2022

So, was it intended that the id column must be in col_select? the id column seems to get unselected if not explicitly selected in col_select.

library(readr); library(tibble)
#> Warning: package 'readr' was built under R version 4.0.5
#> Warning: package 'tibble' was built under R version 4.0.5
testcsv1 <- tibble(a = 1:3, b = 4:6, c = 7:9)
testcsv2 <- tibble(a = 1:3, b = 4:6, c = 7:9)
write_csv(testcsv1, "testcsv1.csv")
write_csv(testcsv2, "testcsv2.csv")
#read_csv(file = c("testcsv1.csv", "testcsv2.csv"), id = "file")
#read_csv(file = c("testcsv1.csv", "testcsv2.csv"), col_select = c("a","b"), id = "file")
#read_csv(file = c("testcsv1.csv", "testcsv2.csv"), col_select = c("a","b","file"), id = "file")
vroom::vroom(file = c("testcsv1.csv", "testcsv2.csv"), id = "file")
#> Rows: 6 Columns: 4
#> -- Column specification --------------------------------------------------------
#> Delimiter: ","
#> dbl (3): a, b, c
#> 
#> i Use `spec()` to retrieve the full column specification for this data.
#> i Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 6 x 4
#>   file             a     b     c
#>   <chr>        <dbl> <dbl> <dbl>
#> 1 testcsv1.csv     1     4     7
#> 2 testcsv1.csv     2     5     8
#> 3 testcsv1.csv     3     6     9
#> 4 testcsv2.csv     1     4     7
#> 5 testcsv2.csv     2     5     8
#> 6 testcsv2.csv     3     6     9
vroom::vroom(file = c("testcsv1.csv", "testcsv2.csv"), col_select = c("a","b"), id = "file")
#> Rows: 6 Columns: 2
#> -- Column specification --------------------------------------------------------
#> Delimiter: ","
#> dbl (2): a, b
#> 
#> i Use `spec()` to retrieve the full column specification for this data.
#> i Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 6 x 2
#>       a     b
#>   <dbl> <dbl>
#> 1     1     4
#> 2     2     5
#> 3     3     6
#> 4     1     4
#> 5     2     5
#> 6     3     6
vroom::vroom(file = c("testcsv1.csv", "testcsv2.csv"), col_select = c("a","b","file"), id = "file")
#> Rows: 6 Columns: 3
#> -- Column specification --------------------------------------------------------
#> Delimiter: ","
#> dbl (2): a, b
#> 
#> i Use `spec()` to retrieve the full column specification for this data.
#> i Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 6 x 3
#>       a     b file        
#>   <dbl> <dbl> <chr>       
#> 1     1     4 testcsv1.csv
#> 2     2     5 testcsv1.csv
#> 3     3     6 testcsv1.csv
#> 4     1     4 testcsv2.csv
#> 5     2     5 testcsv2.csv
#> 6     3     6 testcsv2.csv

Created on 2022-03-08 by the reprex package (v2.0.1)

@ahcyip
Copy link

ahcyip commented Mar 9, 2022

tidyverse/readr#1385

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day
Projects
None yet
Development

No branches or pull requests

2 participants