Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape readLines() function in RStudio

Tags:

r

console

rstudio

Because of the work I do with R, I need to use the readline() function to enter text. The problem comes when sometimes, instead of writting readline() I run readLines() accidentally (due to autocomplete or whatever reason).

Once I have run readLines(), there is nothing I can do to escape the function. I can keep on writing but can't recover a prompt in the console (can't run any code) as I do not know how to close the readLines() function call. Any clues?

Note that this problem only happens in RStudio (and, according to Matt in the comments, Visual Studio).

enter image description here

like image 406
boski Avatar asked May 13 '19 15:05

boski


1 Answers

Not a perfect fix, but you can use debug(). Anytime you do end up calling readLines() by accident, you can just exit browse[2] by typing Q.

debug(readLines)
readline()
asdf

[1] "asdf"

readLines()
debugging in: readLines()
debug: {
    if (is.character(con)) {
        con <- file(con, "r")
        on.exit(close(con))
    }
    .Internal(readLines(con, n, ok, warn, encoding, skipNul))
}

Browse[2]> Q

readline()
asdf

[1] "asdf"

like image 112
Matt Avatar answered Oct 07 '22 12:10

Matt