Can someone provide me with a simple usage case where the on.exit() function's "add" argument is true?
Here is a very simple example
myfun <- function(x){
on.exit(print("first"))
on.exit(print("second"), add = TRUE)
return(x)
}
myfun(2)
#[1] "first"
#[1] "second"
#[1] 2
Also note what happens without the add=TRUE parameter
fun <- function(x){
on.exit(print("first"))
on.exit(print("second"))
return(x)
}
fun(2)
#[1] "second"
#[1] 2
The second call to on.exit removes the first call if you don't add the "add=TRUE".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With