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

Error "r_vector" when defining col_types with readr::cols() #264

Closed
jtrecenti opened this issue Sep 15, 2020 · 3 comments
Closed

Error "r_vector" when defining col_types with readr::cols() #264

jtrecenti opened this issue Sep 15, 2020 · 3 comments

Comments

@jtrecenti
Copy link

jtrecenti commented Sep 15, 2020

Hi! Thanks for this awesome package.

After upgrading to R 4.0 and reinstalling packages, this error started to appear.

Using CRAN and github versions.

ctypes <- readr::cols(.default = readr::col_character())
ex <- vroom::vroom_example("mtcars-4.csv")

# does not work with vroom
vroom::vroom(ex, col_types = ctypes)
#> Error in vroom_(file, delim = delim %||% col_types$delim, col_names = col_names, : r_vector

# works with readr
readr::read_csv(ex, col_types = ctypes)
#> # A tibble: 11 x 12
#>    model       mpg   cyl   disp  hp    drat  wt    qsec  vs    am    gear  carb 
#>    <chr>       <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#>  1 Datsun 710  22.8  4     108   93    3.85  2.32  18.61 1     1     4     1    
#>  2 Merc 240D   24.4  4     146.7 62    3.69  3.19  20    1     0     4     2    
#>  3 Merc 230    22.8  4     140.8 95    3.92  3.15  22.9  1     0     4     2    
#>  4 Fiat 128    32.4  4     78.7  66    4.08  2.2   19.47 1     1     4     1    
#>  5 Honda Civic 30.4  4     75.7  52    4.93  1.615 18.52 1     1     4     2    
#>  6 Toyota Cor… 33.9  4     71.1  65    4.22  1.835 19.9  1     1     4     1    
#>  7 Toyota Cor… 21.5  4     120.1 97    3.7   2.465 20.01 1     0     3     1    
#>  8 Fiat X1-9   27.3  4     79    66    4.08  1.935 18.9  1     1     4     1    
#>  9 Porsche 91… 26    4     120.3 91    4.43  2.14  16.7  0     1     5     2    
#> 10 Lotus Euro… 30.4  4     95.1  113   3.77  1.513 16.9  1     1     5     2    
#> 11 Volvo 142E  21.4  4     121   109   4.11  2.78  18.6  1     1     4     2

Created on 2020-09-15 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       Manjaro Linux               
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/Sao_Paulo           
#>  date     2020-09-15                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source                      
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)              
#>  backports     1.1.9   2020-08-24 [1] CRAN (R 4.0.2)              
#>  bit           4.0.4   2020-08-04 [1] CRAN (R 4.0.2)              
#>  bit64         4.0.5   2020-08-30 [1] CRAN (R 4.0.2)              
#>  callr         3.4.4   2020-09-07 [1] CRAN (R 4.0.2)              
#>  cli           2.0.2   2020-02-28 [1] CRAN (R 4.0.2)              
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.2)              
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 4.0.2)              
#>  devtools      2.3.1   2020-07-21 [1] CRAN (R 4.0.2)              
#>  digest        0.6.25  2020-02-23 [1] CRAN (R 4.0.2)              
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.2)              
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.2)              
#>  fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.2)              
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)              
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)              
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.2)              
#>  hms           0.5.3   2020-01-08 [1] CRAN (R 4.0.2)              
#>  htmltools     0.5.0   2020-06-16 [1] CRAN (R 4.0.2)              
#>  knitr         1.29    2020-06-23 [1] CRAN (R 4.0.2)              
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.2)              
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 4.0.2)              
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 4.0.2)              
#>  pillar        1.4.6   2020-07-10 [1] CRAN (R 4.0.2)              
#>  pkgbuild      1.1.0   2020-07-13 [1] CRAN (R 4.0.2)              
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)              
#>  pkgload       1.1.0   2020-05-29 [1] CRAN (R 4.0.2)              
#>  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.2)              
#>  processx      3.4.4   2020-09-03 [1] CRAN (R 4.0.2)              
#>  ps            1.3.4   2020-08-11 [1] CRAN (R 4.0.2)              
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)              
#>  R6            2.4.1   2019-11-12 [1] CRAN (R 4.0.2)              
#>  Rcpp          1.0.5   2020-07-06 [1] CRAN (R 4.0.2)              
#>  readr         1.3.1   2018-12-21 [1] CRAN (R 4.0.2)              
#>  remotes       2.2.0   2020-07-21 [1] CRAN (R 4.0.2)              
#>  rlang         0.4.7   2020-07-09 [1] CRAN (R 4.0.2)              
#>  rmarkdown     2.3     2020-06-18 [1] CRAN (R 4.0.2)              
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 4.0.2)              
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)              
#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 4.0.2)              
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.2)              
#>  testthat      2.3.2   2020-03-02 [1] CRAN (R 4.0.2)              
#>  tibble        3.0.3   2020-07-10 [1] CRAN (R 4.0.2)              
#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.2)              
#>  usethis       1.6.1   2020-04-29 [1] CRAN (R 4.0.2)              
#>  utf8          1.1.4   2018-05-24 [1] CRAN (R 4.0.2)              
#>  vctrs         0.3.4   2020-08-29 [1] CRAN (R 4.0.2)              
#>  vroom         1.3.1   2020-09-15 [1] Github (r-lib/vroom@00061a5)
#>  withr         2.2.0   2020-04-20 [1] CRAN (R 4.0.2)              
#>  xfun          0.16    2020-07-24 [1] CRAN (R 4.0.2)              
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.2)              
#> 
#> [1] /home/jt/R/x86_64-pc-linux-gnu-library/4.0
#> [2] /usr/lib/R/library
@jimhester
Copy link
Collaborator

The problem is loading readr before vroom, this also came up in #256, you need to use vroom::cols() and vroom::col_character(), or just list(.default = "c") for simplicity.

e.g.

ctypes <- list(.default = "c")
ex <- vroom::vroom_example("mtcars-4.csv")

vroom::vroom(ex, col_types = ctypes)
#> # A tibble: 11 x 12
#>    model       mpg   cyl   disp  hp    drat  wt    qsec  vs    am    gear  carb 
#>    <chr>       <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#>  1 Datsun 710  22.8  4     108   93    3.85  2.32  18.61 1     1     4     1    
#>  2 Merc 240D   24.4  4     146.7 62    3.69  3.19  20    1     0     4     2    
#>  3 Merc 230    22.8  4     140.8 95    3.92  3.15  22.9  1     0     4     2    
#>  4 Fiat 128    32.4  4     78.7  66    4.08  2.2   19.47 1     1     4     1    
#>  5 Honda Civic 30.4  4     75.7  52    4.93  1.615 18.52 1     1     4     2    
#>  6 Toyota Cor… 33.9  4     71.1  65    4.22  1.835 19.9  1     1     4     1    
#>  7 Toyota Cor… 21.5  4     120.1 97    3.7   2.465 20.01 1     0     3     1    
#>  8 Fiat X1-9   27.3  4     79    66    4.08  1.935 18.9  1     1     4     1    
#>  9 Porsche 91… 26    4     120.3 91    4.43  2.14  16.7  0     1     5     2    
#> 10 Lotus Euro… 30.4  4     95.1  113   3.77  1.513 16.9  1     1     5     2    
#> 11 Volvo 142E  21.4  4     121   109   4.11  2.78  18.6  1     1     4     2

Created on 2020-09-15 by the reprex package (v0.3.0)

@jtrecenti
Copy link
Author

jtrecenti commented Sep 15, 2020

Perfect, thanks! I was not aware of the vroom::cols().

Do you think it would be useful to add a comment about that here?

https://github.com/r-lib/vroom/blob/00061a52f2c4dabb832a528a3a84ba46d3d2f453/vignettes/vroom.Rmd#L197

I can make a PR if needed

@jimhester
Copy link
Collaborator

Sure, that sounds like a great idea to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants