Created
April 2, 2020 22:55
-
-
Save aclemen1/6581ab69a3e7878d3276594f9c4968e0 to your computer and use it in GitHub Desktop.
Dynamic prompt for R
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
library(modulr) | |
"aclemen1/tool/prompt/bak" %provides_options% list( | |
prompt = getOption("prompt") | |
) | |
"aclemen1/tool/prompt" %requires% list( | |
bak_ = "aclemen1/tool/prompt/bak" | |
) %provides% { | |
suppressWarnings(suppressPackageStartupMessages(library(tcltk2))) | |
prompt_ <- getOption("prompt") | |
set_ <- function(code) { | |
prompt_ <<- getOption("prompt") | |
eval(substitute(tclTaskSchedule( | |
1000L, | |
options( | |
prompt = paste(code, "> ") | |
), | |
id = "prompt", redo = TRUE)), envir = parent.frame()) | |
Sys.sleep(1.2) | |
invisible(prompt_) | |
} | |
unset_ <- function(old) { | |
function() { | |
tclTaskDelete("prompt") | |
options(prompt = old) | |
} | |
} | |
list( | |
set = set_, | |
set_datetime = function(format = "%c") | |
eval(substitute( | |
set_(format(Sys.time(), .format)), | |
list(.format = format)) | |
), | |
unset = unset_(old = prompt_), | |
reset = unset_(old = bak_$prompt) | |
) | |
} | |
if (.__name__ == "__main__") make()$set_datetime() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment