Open hope-data-science opened 1 year ago
Imagine R keeps a list of commands which need to be executed when exiting. The current implementation allows you to do one of three things:
add=TRUE
, after=TRUE
)add=TRUE
, after=FALSE
)add=FALSE
, after=TRUE
or after=FALSE
)What you have suggested is not wrong, and it even makes sense if you only call on.exit
once in your program, but the arguments of on.exit
are there to support the more general functionality described above.
I can understand your point, some on.exit
might only be executed on condition. In these cases, the argument add
and after
could be used flexibly.
I've learned
on.exit
in the book and it is really helpful. But setting the parameteradd
to TRUE get me a little puzzled, and theafter
argument might just make it harder to know the order of expressions. If the contents inon.exit
would just run in the end, why not wrap them up? Which mean:could be used as:
In this style, we do not have to figure out which codes would be evaluated first. Wonder if this style would be better.
Thanks.