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
bug an unexpected problem or unintended behavior
Milestone

Comments

@elad-custora
Copy link

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

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

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

@romainfrancois romainfrancois added this to the 0.3.1 milestone Oct 17, 2014
@romainfrancois romainfrancois added the bug an unexpected problem or unintended behavior label Oct 17, 2014
@elad-custora
Copy link
Author

Thank you!

@hadley
Copy link
Member

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 commented Nov 19, 2014

This is pretty painful. Hoping for a fix soon.

@hadley
Copy link
Member

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 as completed 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
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants