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
You can create a missing object by using substitute()
without argument.
In your case we could make round1
a missing object in the else
clause :
foo = function(a, round0) {
a = a * pi
if(!missing(round0)) round(a)
else a
}
bar = function(b) {
if(b > 10) round1=T else round1 <- substitute()
foo(b, round1)
}
bar(9)
#> [1] 28.27433
Created on 2019-10-24 by the reprex package (v0.3.0)