How to invoke an R script like the following
scan()
in Windows? When using either R or Rscript, nothing is read. With Rscript or littler (both on Linux) the script works as expected.
# Doesn't work because stdin is already redirected
R --no-save < test.R
# Works on Linux, doesn't on Windows
Rscript test.R
# Works on Linux, doesn't exist in Windows
r test.R
Is there any way at all to achieve this without changing the R code?
Perhaps related: Why is there no --interactive switch in Windows?
So as we discussed in the comments and with confirmation of @nograpes, you can use the following:
in a script instead of
scan()to read interactively from standard input when the script is executed in the command-line interface.You then need to hit Ctrl + Z to end scanning under Windows (Ctrl + D on a Mac).