How to include interactive input in script to be run from the command line

前端 未结 3 518
耶瑟儿~
耶瑟儿~ 2020-12-01 03:47

I am trying to write an interactive R script. For example:

try.R:

print(\"Entr some numbers. >\",quote=F)
a = scan(what=double(0))
print a
q()
         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 04:40

    What worked for me on Windows with RStudio 0.98.945 and R version 3.1.1 was:

        cat("What's your name? ")
        x <- readLines(con=stdin(),1)
        print(x)
    

提交回复
热议问题