提示将输入字符串放入变量 - R

Prompt to put input string to variable - R

我每天 运行 编写一个 R 脚本,希望在 select 编写整个脚本时提示我输入数据。

我已经试过readline(prompt = ),它在rstudio控制台提示,但是如果我select所有代码到运行它不会提示我。我也不喜欢控制台中的提示,因为它很容易被忽视。

我也调查了 library(tcltk),希望消息框能有所帮助,但我尝试过的似乎都不起作用。

这是一个使用 library(tcltk)

的方法
EntryBox <- function(label = 'Enter', title = 'Entry Box') {
    tt <- tktoplevel()
    tkwm.title(tt, title)   
    done <- tclVar(0)
    tkbind(tt,"<Destroy>", function() tclvalue(done) <- 2)
    result <- tclVar("")
    cancel.but <- tkbutton(tt, text='Cancel', command=function() tclvalue(done) <- 2)
    submit.but <- tkbutton(tt, text="Submit", command=function() tclvalue(done) <- 1)
    tkgrid(tklabel(tt, text=label),  tkentry(tt, textvariable=result), pady=3, padx=3)
    tkgrid(submit.but, cancel.but, pady=3, padx=3)
    tkfocus(tt)
    tkwait.variable(done)
    if(tclvalue(done) != 1) result <- "" else result <- tclvalue(result)
    tkdestroy(tt)
  return(result)
}

x <- EntryBox(label = 'Enter a string'); x