This is my code:
empty <- ""
mtcars %>% select(mpg,empty)
Error in `select()`:
! Can't subset columns that don't exist.
✖ Column `` doesn't exist.
The empty object is an output of a for loop. So if empty is equal "" I wouldn't need to select nothing but I get the error bellow.
In other words, I should be able to select something like this: mtcars %>% select(mpg,) . I would need to transform "" to
How can I avoid this error?
Perhaps using
tidyselect::any_ofOr create a new variable and set it to
NULLif it's an empty string: