You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a function, toopt(th, dat). The goal is to minimize the function in terms of its first argument. The second argument is a data.table. I guess this is a pretty common use case.
Inside optim or optimize, the function is called many times as it searches for the optimum.
Sorry if this example is too trivial or abstract. In my actual example, I have a sequence of functions like f that add columns (stored in separate functions so I can isolate them for easier testing and to reduce duplication, since I have multiple toopt functions that are similar but not identical); and my DT has some columns that I don't need for the calculations in toopt.
Besides functions passed to optim, I also use / want to use shallow in other functions, so I can benefit from the efficiency of not making a copy without worrying about whether my input will be messed with (if I didn't use copy) or about whether I need to to prune my input table's columns down to the minimum required for the function (if I did use copy).
The text was updated successfully, but these errors were encountered:
Besides dtplyr #3665, another recent example from SO:
So you want to create a new column in a data.table? Any reason this doesn't work: mtcarsDT[, newcol := myFunc()]? – Andrew 18 hours ago
Yes and No. I don't really want to create a column, I just want to view the result of the expression next to the existing columns without having to save the column and then delete it later – Dean MacGregor 18 hours ago
jangorecki
changed the title
[Request] export shallow or similar
export shallow copy
Jul 30, 2019
I'm posting in response to Matt's SO post and comments below.
I have a function,
toopt(th, dat)
. The goal is to minimize the function in terms of its first argument. The second argument is a data.table. I guess this is a pretty common use case.Inside
optim
oroptimize
, the function is called many times as it searches for the optimum.Sorry if this example is too trivial or abstract. In my actual example, I have a sequence of functions like
f
that add columns (stored in separate functions so I can isolate them for easier testing and to reduce duplication, since I have multipletoopt
functions that are similar but not identical); and myDT
has some columns that I don't need for the calculations intoopt
.Besides functions passed to
optim
, I also use / want to useshallow
in other functions, so I can benefit from the efficiency of not making a copy without worrying about whether my input will be messed with (if I didn't usecopy
) or about whether I need to to prune my input table's columns down to the minimum required for the function (if I did usecopy
).The text was updated successfully, but these errors were encountered: