I'm using select_if to clean up dataframes that are downloaded from external databases. So for instance if I want to trim whitespace from character columns I can write:
df <- select_if(df, is.character, trimws)
and my text fields are trimmed. Since the date fields come down as text ("2018-01-02"), I'd like to write a similar statement that converts them to dates. So I write:
is_date <- function(x) str_detect(x,"^\\d{4}-\\d{2}-\\d{2}")
df <- select_if (df, is_date, ymd)
but I get the enigmatic error:
Error in selected[[i]] <- .p(.tbl[[vars[[i]]]], ...) :
more elements supplied than there are to replace
This feels like one of those strange R list things but I can't make it go away. Anyone know how?
Thanks!