-
Notifications
You must be signed in to change notification settings - Fork 979
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
feature request: proper inplace argument (like in Pandas) #3682
Comments
Actually you could do that quite easily like:
I understand -- I believe you could also do Alternatively, you could add the new column in
|
ah! crazy trick! This should added to the main DT page ! |
Sure thing! The above are all a bit hack-ish (besides the So let's leave this issue open as the place to decide how we want to go about supporting affirmatively what's mentioned here. |
ah ok but do you mean the safest way to do so is with the c(.SD) trick? |
Safest IMO is c(.SD, list(var=val)), I recommend you to understand why the extra 'list' |
thanks! I actually dont undersdant why I need the extra list here. That was working without it?! |
because you're concatenating a list ( |
Just that that is very canonical way to select all-existing-columns-plus-one-new-column & the return is a copy of the original (not updating the original) Just saw Jan's comment with which I agree, I was just trying to be concise but personally I also would do the |
oh I see. then if I have multiple columns I can just type |
yep, as well as defining nontrivial columns by dropping in a full-length vector |
IMO, a shallow copy elegant solves this... but can anybody tell me the reason that |
so to summarize, the best way to work with a copy without the need for the function I defined above (which is actually mentioned in the FAQ) is to use the powerful Thanks!! |
Fyi, #2323 links to SO where Matt's answer and comments might explain. It looks like he was thinking the more elegant way would be to change copy to act like shallow (so the latter can be removed and the user doesn't have to think about the distinction between deep and shallow copies). |
Not sure but one of the reasons might be lack of reference counting mechanism in base R. Actually it is there, implemented, ready, but not enabled. |
Hello there,
Its me again. Sorry for posting all these requests but I am super excited about DT and I feel just a few extra features are missing to make DT absolutely great.
Something that I find quite annoyting when using
:=
is that it operatesin place
by default. This is super annoying because during data work I create new variables all the time (for testing/exploring the data). This does not mean I want these variables to be added to my dataframe!I know I can do something like
but this is really not efficient at all. Could it be possible to add some
inplace = FALSE
like in Pandas so that the output ofDT[, newvar := 'hello', inplace = FALSE][]
prints BUT my DT is not modified? What do you think?
Thanks!!
The text was updated successfully, but these errors were encountered: