How to create shortcut to Rscript on Windows 7

半城伤御伤魂 提交于 2019-12-07 16:53:52

问题


I have created a Windows 7 shortcut in an attempt to give someone who is not comfortable with R the ability to run a simple program. I have tried to follow the advice of other postings, but must be missing something. This is what I have in my shortcut right now.

Target: "C:\Program Files\R\R-3.0.2\bin\x64\Rscript.exe" --vanilla -e "C:\Users\Moo\Desktop\CharCalendar.r"

Start in: "C:\Program Files\R\R-3.0.2\bin\x64"

I get error messages (that flash up very briefly on a black DOS window) that say things like Error unexpected input in "C:\"

I have tried with and without quotes in the target, I have tried using source() in the target (also with and without quotes).

The script runs without error when I submit it in the R console.


回答1:


You probably want

"C:\Program Files\R\R-3.0.2\bin\x64\Rscript.exe" --vanilla C:\Users\Moo\Desktop\CharCalendar.r

as your target. No -e; that specifies an expression to run, not a script file.




回答2:


I must admit, I hardly ever made my own shortcut in Windows. However, you coul seemly write a bat-file which runs the R-script and PAUSES, so you can read the output:

@echo off
"C:\Program Files\R\R-3.0.2\bin\x64\Rscript.exe" "C:\Users\Moo\Desktop\CharCalendar.r"
PAUSE

You may also want to add additional options and arguments after Rscript.exe. If you want to pass it to Rgui.exe, it will be a trickier. Read the following stackoverflow-topic for hints:

Passing script as parameter to RGui




回答3:


Replace Rscript.exe -e with Rterm.exe -f, which indicates that you are passing a file as argument, -e is for passing expressions e.g. Rscript.exe -e "a<-1:10; mean(a);" Rterm provides a few more options for control compared to Rscript, see Rterm.exe --help.



来源:https://stackoverflow.com/questions/19724875/how-to-create-shortcut-to-rscript-on-windows-7

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