I’ve learned that it’s common practice to use optional arguments in function and check them with missing() (e.g. as discussed in SO 22024082)
In this example round0
rlang
provides also a function missing_arg()
that makes an argument be missing.
foo = function(a, round0) {
a = a * pi
if(!missing(round0)) round(a)
else a
}
bar = function(b) {
if(b > 10) round1 <- TRUE else round1 <- rlang::missing_arg()
foo(b, round1)
}
foo(9)
#> [1] 28.27433
bar(9)
#> [1] 28.27433
Created on 2020-12-02 by the reprex package (v0.3.0)