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

group_by returns "Error: index out of bounds" when length of column name is g.t 39 characters #705

Closed
elad-custora opened this issue Oct 16, 2014 · 6 comments
Assignees
Labels
Milestone

Comments

@elad-custora
Copy link

@elad-custora elad-custora commented Oct 16, 2014

When we do:

library('dplyr')
df <- data.frame(a = 1:10, b = 1:10)
names(df) <- c('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'b')
df %>% group_by(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)

All is well. But:

names(df) <- c('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'b')
df %>% group_by(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
Error: index out of bounds
@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Oct 17, 2014

It happens here with lazyeval::auto_name here : https://github.com/hadley/dplyr/blob/master/R/group-by.r#L95

  new_groups <- lazyeval::auto_name(new_groups)

because:

> lazyeval::auto_name
function (x, max_width = 40)
{
    names(x) <- auto_names(x, max_width = max_width)
    x
}
<environment: namespace:lazyeval>

@hadley I understand the truncating is useful for when we are dealing with expression, but perhaps auto_name or auto_names could not truncate when it is a symbol. I'll start a new issue on lazyeval.

@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Oct 17, 2014

Submitted a fix in lazyeval with which I now get:

> df <- data.frame(a = 1:10, b = 1:10)
> names(df) <- c('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'b')
> df %>% group_by(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
Source: local data frame [10 x 2]
Groups: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA  b
1                                        1  1
2                                        2  2
3                                        3  3
4                                        4  4
5                                        5  5
6                                        6  6
7                                        7  7
8                                        8  8
9                                        9  9
10                                      10 10
>
>
> names(df) <- c('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'b')
> df %>% group_by(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
Source: local data frame [10 x 2]
Groups: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA  b
1                                         1  1
2                                         2  2
3                                         3  3
4                                         4  4
5                                         5  5
6                                         6  6
7                                         7  7
8                                         8  8
9                                         9  9
10                                       10 10

@elad-custora
Copy link
Author

@elad-custora elad-custora commented Oct 17, 2014

Thank you!

@hadley
Copy link
Member

@hadley hadley commented Oct 24, 2014

I think I'd rather fix this in select_vars_. Let me think about it a little.

@dchudz
Copy link

@dchudz dchudz commented Nov 19, 2014

This is pretty painful. Hoping for a fix soon.

@hadley
Copy link
Member

@hadley hadley commented Nov 19, 2014

@romainfrancois decided that your approach was the best after all, although I implemented it slightly differently.

@hadley hadley closed this in baf942f Nov 19, 2014
krlmlr pushed a commit to krlmlr/dplyr that referenced this issue Mar 2, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants