Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的Readline()读取下一行_R - Fatal编程技术网

R中的Readline()读取下一行

R中的Readline()读取下一行,r,R,我需要一些用户输入,我想使用readline。但是,当我执行下面的代码时,它使用“testR正在等待输入,并在调用fun()后感知代码(即复制粘贴的代码),例如测试是唯一的选项吗?是,还是逐行复制/粘贴。 fun <- function() { ANSWER <- readline("Are you a satisfied R user? ") if (substr(ANSWER, 1, 1) == "n") cat("This is impossible.

我需要一些用户输入,我想使用readline。但是,当我执行下面的代码时,它使用“test
R
正在等待输入,并在调用
fun()
后感知代码(即复制粘贴的代码),例如
测试是唯一的选项吗?是,还是逐行复制/粘贴。
fun <- function() {
   ANSWER <- readline("Are you a satisfied R user? ")
   if (substr(ANSWER, 1, 1) == "n")
     cat("This is impossible.  YOU LIED!\n")
   else
     cat("I knew it.\n")
}
fun()
test <- "sometext"
someCode <- "someCode"
> fun <- function() {
+   ANSWER <- readline("Are you a satisfied R user? ")
+   if (substr(ANSWER, 1, 1) == "n")
+     cat("This is impossible.  YOU LIED!\n")
+   else
+     cat("I knew it.\n")
+ }
> fun()
Are you a satisfied R user? test <- "sometext"
I knew it.
> someCode <- "someCode"
foo = function(){
    fun()
    test <- "sometext"
    someCode <- "someCode"
}
foo()