Setting read_excel to guess some column types
I am using read_excel
from a batch readxl
to read a file where there are 3 columns that I want to coerce as text, and the rest I'm happy to let the read_excel
type guess. Can I do it?
I tried to use col_type
to set the columns I want to be text
and the rest is like blank
, but this results in the columns being skipped blank
. I tried using NA
instead blank
, but doing so all columns will be bound to text
, when read_excel
otherwise I would read as "number".
My code was
col_filter <- rep('blank', 14)
col_filter[1, 3, 7] <- 'text'
read_excel(file, sheet, col_type=col_filter)
14 is the number of columns in the excel file, 1 3 7 are the columns I want to read as text. Bonus if I can do this without knowing the number of columns beforehand (without reading the file first to check the number of columns).
source to share