rem Run R script with batch file folder as working directory rem Determine the folder where this Linux shell script lives rem - first get the bat file folder rem - then convert single backslashes to forward slashes since R does not like single backslashes set rwd="%~dp0" set "rwd=%rwd:\=/%" echo R working directory from bat file is %rwd% rem Run the R script rem - R is probably in the PATH since it installs to a common bin folder rem - the first use of %rwd% tells R where to find the R script rem - the second use of %rwd% tells the script being run where the script exists rem - all paths in the R script should be absolute using %wd% rem - a more explicit command line option than the first R script argument could be implemented "C:\Program Files\R\R-3.6.1\bin\x64\Rscript" %rwd%/test.R "%rwd%"