Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-syntactic names in select + group_by #1138

Closed
michaelweylandt opened this issue May 15, 2015 · 0 comments
Closed

Non-syntactic names in select + group_by #1138

michaelweylandt opened this issue May 15, 2015 · 0 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@michaelweylandt
Copy link
Contributor

Should dplyr support non-syntactic (backtick-required) names for columns?

Minimal reproducible example:

> data_frame(`a b`=2) %>% group_by(`a b`) %>% select
Error: invalid column index : NA for variable: `a b` = `a b`

The problem seems to be in select_.grouped_df. In particular, it's tripping over the following funny interaction between non-syntactic names / lists / as.character:

> x <- quote(`a b`)
> as.character(x) ## no backticks
[1] "a b"
> as.character(list(x)) ## backticks
[1] "`a b`"
> y <- quote(`ab`)
> as.character(y)
[1] "ab"
> as.character(list(y))
[1] "ab"

Because of the additional backticks, not all elements of include are in names(.data) leading to the error shown above.

Changing to

vars <- select_vars_(names(.data), dots, include = unlist(lapply(groups(.data), as.character)))

appears to fix the problem.

@hadley hadley added this to the 0.5 milestone May 19, 2015
@hadley hadley added the bug an unexpected problem or unintended behavior label Oct 22, 2015
@hadley hadley closed this as completed in 41a666d Mar 8, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants