-
Notifications
You must be signed in to change notification settings - Fork 977
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
Need an easier way to in-place merge multiple columns #3184
Comments
most reliable way as of now will be to use meta programming. Good examples are https://stackoverflow.com/a/37008966/2490497 |
Large overlap as well with #935, including #935 (comment) |
@renkun-ken is there any API you would like to propose? as.call(c(as.name("list"), lapply(paste0("y",1:5), as.name))) the good thing is that, above API relies only on base R, user does not need to learn any new non-base R function or package. |
One idea:
I often do both of these. Avoiding mget would help save keystrokes and avoid finicky edge cases, I guess. Related: #935 (comment) already mentioned above. The summarization/expression syntax would help so that I don't need to type the on= column "id" twice, solving my main use-case for requesting #2061 |
If we want to have |
I think #4304 has already addressed this feature request given that d1[d2, paste0("z", 1:5) := list(y1, y2, y3, y4, y5), on = "id"] could be nicely programmed into d1[d2, paste0("z", 1:5) := Y, on = "id", env = list(Y = as.list(paste0("y", 1:5)))] |
Yes, definitely. I would just add "i." into paste to have more precisely defined columns. Let's close this issue with just a unit test then. |
In-place merge in the form of
dt1[dt2, x := y, on = .(col1, col2)]
is useful whendt1
is very large. It also supports merging multiple columns fromdt2
using`:=`(x1 = y1, x2 = y2)
. However, when I need to merge many columns fromdt2
todt1
, it seems only possible to explicitly list all columns rather than dynamically determine the column names via a character vector like done with.SD
, or otherwise I need to use meta-programming facilities to generate an expression and evaluate it.One simple example is as follows. A practice use case is when
dt1
anddt2
is very large and usingmerge
will cause copy that is very slow and may exceed memory limit (which is exactly why in-place operations are introduced)Another similar problem is to in-place merge all columns of
d2
without specifying source and target columns names.The text was updated successfully, but these errors were encountered: