I try to test an interactive mode in Rstudio:
ans <- readLines("stdin", n = 1)
print(ans)
However the console gets stuck and not accepting any commands. I cannot even quit this mode after that and have to reboot the entire Rstudio. What I do wrong?
CodePudding user response:
Read from stdin()
, not file("stdin")
:
ans <- readLines(stdin(), n = 1)
From ?stdin
:
stdin()
refers to the 'console' and not to the C-levelstdin
of the process. The distinction matters in GUI consoles (which may not have an activestdin
, and if they do it may not be connected to console input), and also in embedded applications. If you want access to the C-level file streamstdin
, usefile("stdin")
.