Search code examples
rioconsoleuser-input

R - readline-prompt over multiple lines


I'm trying to implement a simple selection using the console. This is the code:

n <- readline(prompt = "1 - selection A\n2 - selection B\nInput: ")

And the whole thing is working, but the input is written at the end of the first line, after 'selection A'. I'd like the user input to be at the end of the prompt (after 'Input: '). Thanks!

enter image description here


Solution

  • As Roman has rightly pointed out, your code should work in RGui. In Rstudio, I would use

    cat("1 - selection A\n2 - selection B\n")
    n<-readline(prompt ="Input: ")