When I read a CSV file containing a trailing delimiter using readr::read_csv
, I get a warning that a missing column name was filled in. Here is the contents of a short example CSV file to reproduce this warning (store the following snippet in a file called example.csv
):
A,B,C,
2,1,1,
14,22,5,
9,-4,8,
17,9,-3,
Note the trailing comma at the end of each line. Now if I load this file with
read_csv("example.csv")
I get the following warning:
Missing column names filled in: 'X4'
Even if I want to explicitly load only the 3 columns with
read_csv("example.csv", col_types=cols_only(A=col_integer(),
B=col_integer(),
C=col_integer()))
I still get the warning message.
Is this the expected behavior or is there some way to tell read_csv
that it is supposed to ignore all columns except the ones I specify? Or is there another way to tidy up this (apparently malformed) CSV so that trailing delimiters are deleted/ignored?
cols_only
all columns seem to be imported. I edited my question to include a small example CSV file to show the problem. – cbrnr