How to invoke script that uses scan() on Windows?

亡梦爱人 提交于 2019-12-10 23:56:31

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/13270564/how-to-invoke-script-that-uses-scan-on-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!