3

In readr()/read_csv, how to import data with all columns as character? Thanks!

library(tidyverse)    
read_csv(readr_example("mtcars.csv")))
Progman
  • 16,827
  • 6
  • 33
  • 48
anderwyang
  • 1,801
  • 4
  • 18

1 Answers1

5

You can pick a default column type using:

read_csv(readr_example("mtcars.csv"), col_types = cols(.default = col_character()))

The cols specification will also let you define specific columns as well.

Will Oldham
  • 704
  • 3
  • 13
  • Thanks, I want all columns as character. "Unnamed `col_types` should have the same length as `col_names`. Using smaller of the two. " only return one column – anderwyang Apr 23 '22 at 01:15
  • 1
    Bollocks. I think they changed this behavior at some point. Looks like this will accomplish what you'd like: `read_csv(readr_example("mtcars.csv"), col_types = cols(.default = col_character()))` – Will Oldham Apr 23 '22 at 01:23