Bug 16963 - In ?on.exit, add note that on.exit expressions are evaluated after return() call.
Summary: In ?on.exit, add note that on.exit expressions are evaluated after return() c...
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Documentation (show other bugs)
Version: R 3.2.4
Hardware: All All
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-06-22 17:29 UTC by Tim Hesterberg
Modified: 2016-06-22 17:29 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Hesterberg 2016-06-22 17:29:19 UTC
I suggest adding a note at the end of the Details section of help(on.exit) indicating:

Expressions are evaluated after the function's return value is evaluated, so on.exit cannot be used to modify the return value.

Here is an example (which you could add to the Examples section, but I don't think it is worth it):

f <- function() {
  result <- list(a = 1)
  on.exit(result$b <- 2)
  return(result)
}
f()
# only includes $a, not $b.