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

Bug: .GRP should create column named GRP, not .GRP (a la .I, .N) #1243

Closed
MichaelChirico opened this issue Jul 22, 2015 · 5 comments
Closed

Comments

@MichaelChirico
Copy link
Member

That .GRP returns a variable named .GRP by default is causing some errors.

Consider:

data.table(id=rep(1:3,each=5),yr=rep(rep(1:3,3),rep(c(2,1,2),3)))[,.GRP,by=.(id,yr)][,!.GRP%in%range(.GRP),by=id]

(Basically, trying to eliminate the first and last yr of observation from each id)

This is an error: cannot change value of locked binding for '.GRP'. I can think of a number of workarounds, but it seems the simpler solution is to simply change the naming behavior.

I imagine this is the same reason why .I and .N return columns named I and N by default.

@eantonya
Copy link
Contributor

I haven't thought this through very carefully, but I assume whatever argument applies to .GRP also applies to .BY.

@jangorecki
Copy link
Member

Not sure but maybe it is only a matter of adjusting regex in two lines of [.data.table:
jvnames = gsub("^[.]([NI])$","\\1",as.character(jsub)) in data.table.R#L896
jvnames[jj-1L] = gsub("^[.]([NI])$","\\1",deparse(jsubl[[jj]])) in data.table.R#L907

@MichaelChirico
Copy link
Member Author

@jangorecki perhaps these lines as well

@arunsrinivasan
Copy link
Member

@MichaelChirico no, just the ones Jan's pointed. Would be great to wrap this up..

@MichaelChirico
Copy link
Member Author

@arunsrinivasan gonna take care of it now. Is there anything that needs to be changed in the tests / manual for this?

arunsrinivasan added a commit that referenced this issue Sep 11, 2015
Closes #1243: auto names .GRP/.I properly as GRP/I.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants