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

col_types is processed differently by read_*() and type_convert() #1509

Open
chainsawriot opened this issue Aug 22, 2023 · 1 comment
Open

Comments

@chainsawriot
Copy link

In the documentation, col_types appears to be processed the same way by read_*() and type_convert().

type_convert() cannot process "-" (skip).

readr::read_csv(I("a,1,1\nb,1,2\nc,1,2"), col_names = c("a", "b", "c"), col_types = "f-i")
#> # A tibble: 3 × 2
#>   a         c
#>   <fct> <int>
#> 1 a         1
#> 2 b         2
#> 3 c         2

df <- tibble::tibble(a = c("a", "b", "c"),
                     b = c("1", "1", "1"),
                     c = c("1", "2", "2"))
readr::type_convert(df, col_types = "f-i")
#> Warning: Insufficient `col_types`. Guessing 1 columns.
#> Error in if (is.na(name)) {: argument is of length zero
sessionInfo()
#> R version 4.3.1 (2023-06-16)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 22.04.3 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=de_DE.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: Europe/Berlin
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] crayon_1.5.2      vctrs_0.6.3       cli_3.6.1         knitr_1.43       
#>  [5] rlang_1.1.1       xfun_0.40         purrr_1.0.2       styler_1.10.1    
#>  [9] bit_4.0.5         glue_1.6.2        htmltools_0.5.6   hms_1.1.3        
#> [13] fansi_1.0.4       rmarkdown_2.24    R.cache_0.16.0    evaluate_0.21    
#> [17] tibble_3.2.1      tzdb_0.4.0        fastmap_1.1.1     yaml_2.3.7       
#> [21] lifecycle_1.0.3   compiler_4.3.1    fs_1.6.3          pkgconfig_2.0.3  
#> [25] R.oo_1.25.0       R.utils_2.12.2    digest_0.6.33     R6_2.5.1         
#> [29] tidyselect_1.2.0  utf8_1.2.3        reprex_2.0.2      readr_2.1.4      
#> [33] parallel_4.3.1    vroom_1.6.3       pillar_1.9.0      magrittr_2.0.3   
#> [37] R.methodsS3_1.8.2 bit64_4.0.5       tools_4.3.1       withr_2.5.0

Created on 2023-08-22 with reprex v2.0.2

@jennybc
Copy link
Member

jennybc commented Sep 15, 2023

Once readr 2e was introduced, which basically means that by default readr is a front end for vroom, there is no longer any real connection between type_convert() (readr 1e code) and the code hit via read_*() (readr 2e = vroom). And thus small discrepancies start to creep in like this.

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

No branches or pull requests

2 participants