Skip to content

Commit

Permalink
add another example
Browse files Browse the repository at this point in the history
  • Loading branch information
robertzk committed Mar 1, 2015
1 parent 4b1a03f commit 44728a5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Expand Up @@ -64,3 +64,41 @@ if (!require("devtools")) install.packages("devtools")
devtools::install_github("robertzk/super")
```

Another example
===============

Note that `super` merely looks up the parent environment chain of the calling frame.
Thus, we can use it for local functions as well as attached packages.

```R
function1 <- function() {
print("Top-level")
invisible(NULL)
}

local({
function2 <- function() {
function1 <- function() {
print("Mid-level")
super::super()
}

function3 <- function() {
function1 <- function() {
print("Low-level")
super::super()
}
function1()
}

function3()
}

function2()
})
# Will print
# [1] "Low-level"
# [1] "Mid-level"
# [1] "Top-level"
```

0 comments on commit 44728a5

Please sign in to comment.