In read_csv(), how to combine use `col_names = TRUE` and `col_character`

121 Views Asked by At

In readr, where combine using parameter col_names = TRUE and col_character as below code3, it's failed and the error message as attached image. Anyone can help on this ? Thanks!

library(tidyverse)    
# code1 ok    
    read_csv("a,b,c
        1,2,3
        4,5,6",col_character)
    
    # code2 ok      
        read_csv("a,b,c
        1,2,3
        4,5,6",col_names = TRUE)
    
    # code3 :failed   
        read_csv("a,b,c
        1,2,3
        4,5,6",col_names = TRUE,col_character)

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

wrap it around cols, e.g.

readr::read_csv("a,b,c
        1,2,3
        4,5,6",
  col_names = TRUE,
  col_types = readr::cols(.default = col_character())
)