-
Notifications
You must be signed in to change notification settings - Fork 992
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
names(.SD) := ... should work #795
Comments
That would be very nice. |
Alternate is to create a Also, using |
the straight "workaround" for this would be to use still the |
Jan, not sure
or
equivalently, though this is a good reminder that
|
Another inconsistency with this currently is that this works: A<-data.table(x=1:10,y=10:1,z=rnorm(10))
A[,`:=`(colnames(A),.SD)] and this doesn't: A[,`:=`(colnames(.SD),.SD)] The second fails with:
That precludes some elegant .SDcols syntax. |
Unfortunate that this workaround is blocked by
It's unfortunate since the result of
|
I actually lean towards allowing
That & whatever comes out of #3795 would make adding/editing many columns much less clunky |
or eventually which is more like DT[ , .SDcols := lapply(.SD, rev), .SDcols = -c(1,3,8)] |
I've been thinking about this FR again after having to do quite a bit of "manual" LHS creation in a current project. (FWIW my own preferred option is @MichaelChirico's Another possible syntax variant — which would involve even less typing if it is feasible to code up — would be to enable DT[ , lapply(.SD, rev), .SDcols := c(1,3,8)] |
It does ~basically read well here, but I would be against that... |
This would allow the following type of code:
DT[, names(.SD) := lapply(.SD, rev), .SDcols = -c(1,3,8)]
To reverse every column except 1, 3, and 8 in
DT
by reference. See discussion in #787. Maybe potentially even:DT[, := lapply(.SD, rev), .SDcols = -c(1,3,8)]
and have the names of the columns to be updated inferred from the names of the return value to
lapply
.The text was updated successfully, but these errors were encountered: