David -4 years ago 132
R Question

Executing a batch file in an R script

I would like to execute a batch file from a R script. The file is in a directory like

\\network\path\to\batch\file.bat
.

I know I can use the
system
command in R to run DOS commands but I can't simply use
system("start file.bat")
. So how would I best use R script to execute this batch file?

Try shell.exec("\\\\network\\path\\file.bat")
The shell.exec command uses the Windows-associated application to open the file. Note the double back-ticks.
Pro tip: write.csv(file='tmp.csv',tmpdat);shell.exec('tmp.csv') is useful (assuming you've associated CSV files with your preferred application for viewing CSV files) for quickly checking output.