Search code examples
rr-packagerlang

best practices for using bang-bang (!!) and walrus (:=) inside package functions


Best practices when writing a new package is to call other package functions using the package::function() syntax and keeping the namespace clean. What is the equivalent operation for telling R to use rlang's !! and := when I'm using them inside a a package's function, since they have no functional form? Using load_all() things seem to work fine but I want to make sure they're not just working because something else loaded rlang already into my path.


Solution

  • They do not need importing:

    From Advanced R

    . !! and !!! behave specially inside all quoting functions powered by rlang, where they behave like real operators with precedence equivalent to unary + and -. This requires considerable work inside rlang, but means that you can write !!x + !!y instead of (!!x) + (!!y).

    From a previous question

    Once an rlang function detects this "operator" it treats it differently to perform the tidy evaluation necessary (which is why the operator is only useful in a rlang context) ... This is why you only need to import the rlang function you want, because the logic for dealing with !! lies inside rlang internals, not a separate function

    https://stackoverflow.com/a/55764077/10725960