Question

In linux I used to put !#/usr/bin/Rscript so I can call myScript.R [options] on windows replacing the /usr path by the correct path C:/Program... does not work (nothing is happening). The only way I know is to do Rscript.exe myScript.R [options]. Is it possible to mimic the Unix behaviour ?

Was it helpful?

Solution

If you are using the default cmd.exe shell on Windows and are willing to use a second file then you can create a batch file, myScript.bat, containing this line:

Rscript.exe myScript.R %*

and then run it like this:

myScript

You can include arguments at the end of this line but they should not include embedded spaces.

OTHER TIPS

Grothendieck is right. I'll show another idea to mix the two files.

rem <- function(...) invisible(T)
rem( '
Rscript.exe %~F0
EXIT /B
rem ')
### above=BAT, below=R

cat('Hello, World', file='hello.txt')

Save this as "hello.bat" and execute it. You can find more details in my blog.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top