R 中类似Python中raw_input 的函数

Python 中的raw_input 函数在需要用户与计算机交互时非常有用,其实R 里面也一直有一个类似的函数:readline

例如,我现在做出了一个图,想要在图上面找到一个值来决定我在什么地方分割。而实事实上,如果写成函数的话,又必须每次都要更新不同的值,如果此时能够有readline的话,我们就可以直接看着图来进行确认:

我使用下面的代码进行尝试:这样,最终经过三次尝试,我选定0.3作为分割点,把GO_ON改为‘yes',这样程序继续进行。

  GO_ON = 'no'
  while (GO_ON != 'yes'){
    NSF_Cut = as.numeric(readline('please enter an IQR value as the non-specific filtering cutoff: '))
    abline(v= NSF_Cut)
    GO_ON = readline(" Can we go on? \tplease enter 'yes' or 'no': ")
  }
  print (paste('NSF_Cut =',NSF_Cut))
 

posted on 2013-03-28 06:52  Forever_YCC  阅读(286)  评论(0编辑  收藏  举报

导航