So as we discussed in the comments and with confirmation of @nograpes, you can use the following:
scan(file("stdin"), what=character())
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).