How to compress a function from eval(parse(text='5+5')) to eval2('5+5'), so as not to write 3 words each time instead of one?
I use this construction very often, I need to compress it.
UPD: Complicating the case, because packing eval into a function does not work, for example, with data.table. I would like eval(parse(text=)) to turn into eval() in this case:
dt <- data.table(a = c(1, 1, 1, 1), foo_col = c('a', 'b', 'X', 'asd')) cur_col <- 'foo_col2' dt[, eval(parse(text=glue::glue('{cur_col} := c(3, 3, 3, 3)')))] P.S.: The design dt[, (cur_col) := c(3, 3, 3, 3)] does not suit. On it, data.table in an exotic case complains about unnecessary copying.
But it does not complain when using eval(parse(text=
In addition, I often use this construction in principle, so I want to bring it to mind.
fortunes::fortune("parse")not workdata.table? Because that has different rules than normal R syntax.eval(parse(...))should be avoided."fortunes::fortune(106)instead.