Column Name with Spaces in cols_only

28 views
Skip to first unread message

BHM

unread,
May 11, 2017, 3:20:33 PM5/11/17
to manipulatr
Hi,

PROBLEM:

I have a data file with columns that can be ignored, hence the use case for "cols_only"

However these column names have spaces and my code, as follows:

df.temp = read_file(c.csv.temp.file) %>%
  str_replace_all('"{2,3}', '"') %>%
  read_csv(col_names = TRUE,
           col_types = cols_only(tripduration = col_integer(), 
                                 starttime = col_datetime("%d/%m/%Y %H:%M"),
                                 start station id = col_integer()))

returns:

Error: unexpected symbol in:
"                                 starttime = col_datetime("%d/%m/%Y %H:%M"),
                                 start station"


A sample input csv.file is attached. 

Thanks for the help


Br / 
temp.csv

BHM

unread,
May 11, 2017, 3:23:35 PM5/11/17
to manipulatr
The following works:

df.temp = read_file(c.csv.temp.file) %>%
  str_replace_all('"{2,3}', '"') %>%
  read_csv(col_names = TRUE,
           col_types = cols_only(tripduration = col_integer(), 
                                 starttime = col_datetime("%d/%m/%Y %H:%M"),
                                 "start station id" = col_integer()))

adding quote to the col name  ... 
Reply all
Reply to author
Forward
0 new messages