Skip to content

Instantly share code, notes, and snippets.

@moodymudskipper
Created April 1, 2024 15:47
Show Gist options
  • Save moodymudskipper/6a95f134a7230832bee92862b0dfc9b9 to your computer and use it in GitHub Desktop.
Save moodymudskipper/6a95f134a7230832bee92862b0dfc9b9 to your computer and use it in GitHub Desktop.
April 1st
# 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