Created
July 1, 2019 16:21
-
-
Save AkselA/d47736399e5d8f3783fc2d96fe991b74 to your computer and use it in GitHub Desktop.
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
selfdestructor <- function(x) { | |
if (is.numeric(x)) { | |
fn <- paste0("selfdestructor_", x, "k") | |
} else { | |
fn <- paste0("selfdestructor_", x) | |
} | |
f <- function() { | |
message("You specified: x = ", x) | |
rm(list=fn, envir=.GlobalEnv) | |
message("Poof!") | |
} | |
assign(fn, f, envir=.GlobalEnv) | |
message("Assigned '", fn, "' to global environment.\n", | |
"You can run ", fn, "(), but be careful: it self-destructs!\n") | |
gfn <- as.character(match.call())[1] | |
message("This function, ", gfn, ", will self-destruct in") | |
for (i in 5:1) { | |
cat(i, "\n") | |
system2("sleep", "1") | |
} | |
rm(list=gfn, envir=.GlobalEnv) | |
message("Floof!") | |
} |
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
selfdestructor("Oh_no") | |
# Assigned 'selfdestructor_Oh_no' to global environment. | |
# You can run selfdestructor_Oh_no(), but be careful: it self-destructs! | |
# | |
# This function, selfdestructor, will self-destruct in | |
# 5 | |
# 4 | |
# 3 | |
# 2 | |
# 1 | |
# Floof! | |
selfdestructor_Oh_no() | |
# You specified: x = Oh_no | |
# Poof! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment