This is the main reason for this behavior. To fix the problem, the answer to @akrun is probably more appropriate.
Most dplyr functions use lazyeval internally. And the character method for lazyeval::as.lazy cannot handle spaces. A possible solution would be to add around character strings with spaces inside as.lazy.character`.
require(lazyeval) as.lazy.character <- function (x, env = baseenv()){ if (grepl(pattern = "[:space:]", x) & !grepl(pattern = "`", x)) x <- paste0("`", x, "`") lazy_(parse(text = x)[[1]], env) }
Or even better (from @hadley's suggestion)
as.lazy.character <- function (x, env = baseenv()){ if (grepl(pattern = "[:space:]", x) & !grepl(pattern = "`", x)) return(as.lazy(as.name(x), env)) lazy_(parse(text = x)[[1]], env) }
This fixes rename_ as well as any other functions using as.lazy inside:
dplyr::select_vars_(names(df), "test col") dplyr::rename_(df, foo="test col") dplyr::mutate_(df, "foo" = "test col" )
source share