Make R (statistics package) wait for keyboard prompt when run within a bash script

前端 未结 5 915
别跟我提以往
别跟我提以往 2021-02-15 13:14

I am using R to generate a series of plots within a loop, with the user hitting the enter key to indicate they have seen the plot and it is time to move on. These are interacti

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-15 14:00

    Here is an example script that works for me (tested your first calling method on windows). It uses the tcltk package and creates an extra, small window with a single button, the script will pause (but still allow you to interact with the rgl window) until you either click on the 'continue' button on press a key while that window is active, then continue with the script.

    library(tcltk)
    library(rgl)
    
    mywait <- function() {
        tt <- tktoplevel()
        tkpack( tkbutton(tt, text='Continue', command=function()tkdestroy(tt)),
            side='bottom')
        tkbind(tt,'', function()tkdestroy(tt) )
    
        tkwait.window(tt)
    }
    
    
    x <- rnorm(10)
    y <- rnorm(10)
    z <- rnorm(10)
    
    plot3d(x,y,z)
    
    mywait()
    
    x <- rnorm(100)
    y <- rnorm(100)
    z <- rnorm(100)
    
    plot3d(x,y,z)
    
    mywait()
    
    cor(x,y)
    

提交回复
热议问题