-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
issue203.r
30 lines (28 loc) · 893 Bytes
/
issue203.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# The following defines a function which has a function inside its body. This is
# *different* from a nested function; that is, `f` is different from
#
# f1 = function () { identity }
#
# … because `f1` contains a *name* in its body. Likewise, it is different from
#
# f2 = function () { function (x) x }
#
# … because `f2` contains a *call expression* which, when executed, *defines* a
# function, in its body. That is:
#
# class(body(f)[[2L]]) == 'function'
# class(body(f1)[[2L]]) == 'name'
# class(body(f2)[[2L]]) == 'call'
f = function () { NULL }
body(f)[[2L]] = identity
#' `g` clearly isn’t a generic even though `UseMethod` is used inside a nested
#' function in its body.
#' @export
g = function (x) {
nested = function () UseMethod('nested')
nested()
}
#' … nor is `h`.
#' @export
h = function () { NULL }
body(h)[[2L]] = function () UseMethod('foo')