I can't figure out how to use SE dplyr function with invalid variable names, for example selecting a variable with a space in it.
Example:
df <- dplyr::data_frame(`a b` = 1)
myvar <- "a b"
If I want to select a b
variable, I can do it with dplyr::select(df, `a b`)
, but how do I do that with select_
?
I suppose I just need to find a function that "wraps" a string in backticks, so that I can call dplyr::select_(df, backtick(myvar))
As MyFlick said in the comments, this behaviour should generally be avoided, but if you want to make it work you can make your own backtick wrapper
EDIT: Hadley replied to my tweets about this and showed me that simply using
as.name
will work for this instead of using backticks: