This is experimental and writes to the calling frame, which, if in interactive mode, is probably the global environment. We write to a horrible and unusual (although well-known) variable name, which will avoid name conflicts.
bang_dollar()
Returns the evaluated value of the first argument to first argument
of the previous R command, if it was a function call with parentheses.
Primarily, the function is invoked for its side effect of adding of
modifying !$
in the global environment.
http://kevinushey.github.io/blog/2015/02/02/rprofile-essentials/