readr: Skip empty columns

Hi all,

Anyone knows if there's an easy way to tell read_csv to skip empty columns?

Often when handling stuff on Excel the file gets saved with an extra empty column, which gets read as all NA's. For example:

> x <- read_lines('example.csv')
> x
[1] "Some,Example,Here" ",,"                "A,B,"              "1,a,"             
[5] "2,b,"              "3,c,"             
> y <- read_csv('example.csv', skip = 2)
Parsed with column specification:
cols(
  A = col_integer(),
  B = col_character(),
  X3 = col_character()
)
> y
# A tibble: 3 x 3
      A B     X3   
  <int> <chr> <chr>
1     1 a     NA   
2     2 b     NA   
3     3 c     NA 

Use cols() or cols_only():

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.