-
Notifications
You must be signed in to change notification settings - Fork 990
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
FR: auto-infer LHS of := when absent #1543
Comments
Seconding @MichaelChirico here. But I imagine that it's somewhat cumbersome to pull off since In reworking some of the functions for "splitstackshape", I've written the following wrapper functions (both of which will probably use
and
With @MichaelChirico's example, the approach would be:
(Or, of course just using |
@mrdwab thanks for the feedback! Indeed I had thought about how to implement this a bit but was stymied -- the only other function I know of that accepts can assign things is Of course if this is possible this is the way to go:
If not, an alternative would be to add a
And used like
|
I think this should be a general feature of DT[, `:=`(tstrsplit(x, "/", fixed = TRUE))]
DT
# x y z x_1 x_2 x_3 x_4
# 1: a/b/c/d 1 4 a b c d
# 2: a/b/c 2 5 a b c NA
# 3: a/b 3 6 a b NA NA This could be a truly awesome feature that will make our lives much easier when the number of columns is unknown. It will also make the code much more concise. This could be generalized to other DT[, `:=`(shift(y, 1:.N))]
DT
# x y z x_1 x_2 x_3 x_4 y_1 y_2 y_3
# 1: a/b/c/d 1 4 a b c d NA NA NA
# 2: a/b/c 2 5 a b c NA 1 NA NA
# 3: a/b 3 6 a b NA NA 2 1 NA The only caveat I see here, that it could override existing columns. In that case it should return an error, or generate a bit different column names- that part needs to be figured out. |
@DavidArenburg good point. do you happen to know if there's an outstanding FR for that? seems like an obvious one, after all... if not, I'll change the title of this one. |
Maybe update this SO question if this is implemented. |
Another SO post, asking to do it by group (so the workaround "answer" for the last one I linked doesn't work): https://stackoverflow.com/q/51861038
I know there's a warning about the inefficiency of returning named lists in |
Following up on @DavidArenburg 's suggested approach, the more natural R way to accomplish this would I think be through This is a bit redundant -- there's a reason we can't use
And |
Another SO post here: @MichaelChirico Is it really not possible to hack in a way for |
Since j already gets substituted, we could just add a switch for when |
I think it could be doable but I'm not a big fan... (1) added NSE maintenance overhead and (2) i usually avoid |
Yeah as someone familiarizing myself with the |
Throwing in my 2c here, could the
(or something better named than |
It's something of a nuisance to assign ragged columns with
tstrsplit
, if we don't necessarily know how many columns will result ex ante. Is it possible to add anassign
argument which would use:=
orset
to add the result as extra columns to the table?Workaround (ugly)
Inspired by this SO question
The text was updated successfully, but these errors were encountered: