readr: Skip empty columns - redux

Greetings all
I’ve got a followup question to the closed conversation:
readr: Skip empty columns

@leobarlach asked about how to skip empty columns with read_csv
@martin.R provided a good answer about using cols() and cols_only()

My follow up question is what if you don't know which column(s) are empty before reading the data?


If you don't know what column to tell readr to skip, I think you need to read all then select only the non empty column afterward. readr would have to do that if it was possible to tell it to skip.

If you have a lot of column to skip, you can read everything as character (without parsing), filter out the empty colum, then parse the resulting table (see readr::type_convert())

@cderv Thanks for information. I will look into this.


I don't think there's something like skip_empty_cols = TRUE.

You can try the remove_empty function from janitor package.

1 Like

This is exactly what I was hoping to find.
Thank you.

This topic was automatically closed 7 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.