On UNIX one can use #! notation. It would be nice to be able to do something similar on Windows. This could be done by giving Rscript the capability of skipping over the first few lines. For example, there might be a --skip=n argument or perhaps Rscript would skip over any consecutive leading lines that begin with @ in the R file since that cannot be syntactically correct R but does have meaning to Windows batch, namely, it means do not display the line beginning with @ (but still run it). For example, if we implement the @ idea then a sample 3 line file called grep.bat might look like this: @Rscript grep.bat %1 for(L in grep(commandArgs(TRUE), readLines(file("stdin")), value = TRUE)) cat(L, "\n", sep = "") and then we would run it as a Windows batch file like this from the Windows console to find all lines with the word target: grep target < myfile.txt or if we implemented --skip it might look like this: @Rscript --skip=1 grep.bat %1 for(L in grep(commandArgs(TRUE), readLines(file("stdin")), value = TRUE)) cat(L, "\n", sep = "")
ActivePerl has '-x' switch which tells it to skip all lines in the file till "#!". This allows writing perl scripts in ordinary .bat files. ?shQuote contains a link with the following perl script example: ===8<==@echo off :: hello.bat :: Windows executable Perl script :: Note: :: assumes perl.exe is in path :: otherwise, use absolute path perl -x -S "%0" %* goto end #!perl print "Hello, World!\n"; __END__ :end :: ------ end of hello.bat ------ Windows Notes: " -x " (lower case x): Skip all text until shebang line. " -S " (upper case S): Look for script using PATH variable. Special meaning in Windows: appends .bat or .cmd if lookup for name fails and name does not have either suffix. " %* " only on WinNT/2K/XP; use %1 %2 . . . %9 on Win9x/DOS ===8<== I think the simplest way to implement shebang on windows would be embedding one more command line switch with similar functionality to perl's '-x'. -- View this message in context: http://www.nabble.com/Rscript-on-Windows-tf3120774.html#a8651815 Sent from the R devel mailing list archive at Nabble.com.