This seems silly and I'm not sure why I haven't encountered it before, but what patterns/functions do folks here use for inline list element assignment within a magrittr-style pipeline?
Example: I want to inject a timestamp into some object:
x <- list(foo = 1:3) x$dt <- lubridate::now() f(x) ## now go do something with x
But ideally I'd like to inject that timestamp like so (with some hypothesized
x %>% inject(dt = lubridate::now()) %>% f()
assign_in function does this in a very nice 'plucky' way, but requires the location to already exist in the target data. (In the example above the
dt element is novel, triggering an error in
I can obviously write my own minimal wrapper to do this, but I'm curious if there's already a function or operator out there of which I'm just not aware. I'm a fan of the
pluck semantics, so it would ideally follow that pattern and either replace the element's value or append the element (depending on whether or not the element exists already).