Created
April 1, 2024 15:47
-
-
Save moodymudskipper/6a95f134a7230832bee92862b0dfc9b9 to your computer and use it in GitHub Desktop.
April 1st
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
# this will rotate the values of your variables in the global env at each | |
# garbage collection | |
local({ | |
april1st <- function() { | |
e <- new.env() | |
reg.finalizer(e, function(e) { | |
april1st() | |
nms <- ls(.GlobalEnv) | |
objs <- mget(nms, .GlobalEnv) | |
objs <- setNames(objs, c(nms[-1], nms[1])) | |
list2env(objs, .GlobalEnv) | |
}) | |
gc() # necessary not to have GC itself interfer with our magic | |
invisible(NULL) | |
} | |
april1st() | |
}) | |
# this will print a line "I know what you did <user name>" for 0.5 sec, then remove it, | |
# on each garbage collection | |
local({ | |
april1st <- function() { | |
e <- new.env() | |
reg.finalizer(e, function(e) { | |
april1st() | |
msg <- sprintf("I know what you did %s", Sys.info()[["user"]]) | |
n <- nchar(msg) + 1 | |
message(msg) | |
Sys.sleep(0.5) | |
cat(strrep("\b", n), strrep(" ", n),"\n") | |
}) | |
gc() # necessary not to have GC itself interfer with our magic | |
invisible(NULL) | |
} | |
april1st() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment