Last active
August 25, 2016 12:07
-
-
Save renkun-ken/5aa628f5ab4f24b81847372d4111b01a to your computer and use it in GitHub Desktop.
hide-source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e <- new.env() | |
makeActiveBinding("private_f", function(x) { | |
if (missing(x)) { | |
NULL | |
} else { | |
sum <- 0 | |
for (i in 1:x) { | |
sum <- sum + i | |
} | |
e$res <- sum | |
} | |
}, e) | |
public_f <- function(x) { | |
e$private_f <- x | |
e$res | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hide_src <- function(f) { | |
env <- attr(attr(f, "srcref"), "srcfile") | |
env$lines <- "" | |
env$filename <- "" | |
env$original$lines <- "" | |
f | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
secure <- function(f) { | |
e <- new.env(parent = environment(f)) | |
eval(substitute(makeActiveBinding("private", function(x) { | |
if (missing(x)) NULL | |
else e$result <<- f | |
}, e), list(f = body(f)))) | |
rm(f) | |
function(x) { | |
e$private <- x | |
e$result | |
} | |
} | |
#' ftest | |
#' @name ftest | |
#' @export | |
NULL | |
delayedAssign("ftest", secure(function(x) x + 100), environment(), environment()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
secret <- function(expr) { | |
expr <- substitute(expr) | |
e <- new.env(parent = parent.frame()) | |
e$result <- NULL | |
private <- function(x) {} | |
body(private) <- substitute({ | |
if (missing(x)) NULL | |
else result <<- expr | |
}, list(expr = expr)) | |
environment(private) <- e | |
makeActiveBinding("private", private, e) | |
lockEnvironment(e) | |
public <- function(x) { | |
private <<- x | |
result | |
} | |
environment(public) <- e | |
rm(expr, private, e) | |
public | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
secure <- function(f) { | |
e <- new.env(parent = environment(f)) | |
eval(substitute(makeActiveBinding("private", function(x) { | |
if (missing(x)) NULL | |
else e$result <- f | |
}, e), list(f = body(f)))) | |
rm(f) | |
function(x) { | |
e$private <- x | |
e$result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment