18.10 Constructing

  • You can construct a call object from its components using rlang::call2().
  • The first argument is the name of the function to call (either as a string, a symbol, or another call).
  • The remaining arguments will be passed along to the call:
call2("mean", x = expr(x), na.rm = TRUE)
#> mean(x = x, na.rm = TRUE)
call2(expr(base::mean), x = expr(x), na.rm = TRUE)
#> base::mean(x = x, na.rm = TRUE)
  • Infix calls created in this way still print as usual.
call2("<-", expr(x), 10)
#> x <- 10