title: Batch file oddly looping through subsection of R file
body: <p>I have a batch file <code>test.bat</code> on my windows desktop with the following content:</p>
  
  <pre><code>cd /d W:\r\dev\
  "C:\Program Files\R\R-3.5.0\bin\i386\Rscript.exe"  scripts\some_function.R
  </code></pre>
  
  <p>When executed, the referenced R script <code>some_function.R</code> begins to run and outputs messages to the console to let me know where it is. However, it stops after reaching a certain point in the R code then starts over and continues to do so until the session auto-terminates.</p>
  
  <p>I've inspected the R code for an indication of why the batch file would continue to return to the beginning and I've found none. The R file works fine when run directly (from within R studio, for example).</p>
  
  <p>I'm well aware that <a href="https://stackoverflow.com/a/38434127/1393860">naming the batch file with a command that appears in the file can be problematic</a>, but that's not what is happening here. I've tried multiple names for the batch file but that doesn't seem to solve the problem.</p>
  
  <p>Below is the beginning of the code in the referenced file <code>some_function.R</code> that keeps getting re-executed:</p>
  
  <pre><code>library(data.table)
  
  dir &lt;- gsub(x= getwd(), pattern = "(.:/r/)(.*)",replacement = "\\1")
  envir &lt;- gsub(x= getwd(), pattern = "(.:/r/)(\\w+)",replacement = "\\2")
  
  cat(paste("directory = "),dir,"\n","environment = ",envir,"\n")
  
  
  ##############################################################
  # Load System Parameters                                     #
  ##############################################################
  
  cat("Loading system parameters ...","\n")
  
  sys_param_file_path &lt;- paste0(dir,"shared/files/system/sys_param.csv")
  sys_params &lt;- data.table(read.csv(sys_param_file_path, stringsAsFactors = FALSE))
  sys_params &lt;- sys_params[param_envir == envir,]
  
  for(i in 1:nrow(sys_params)){
    if(sys_params[i,param_type] == "environment path"){
      sys_params[i,param_val := paste(dir,envir,param_val,sep = "")]
    }
    if(sys_params[i,param_type] == "root path"){
      sys_params[i,param_val := paste(substr(dir,1,nchar(dir)-1),param_val,sep = "")]
    }
  }
  
  cat(paste("Loaded",nrow(sys_params),"parameters","\n"))
  </code></pre>
  
  <p>and the console output when the batch file is called:</p>
  
  <pre><code>C:\Users\me\Desktop&gt; cd /d W:\r\dev\
  
  W:\r\dev&gt;"C:Program Files\R\R-3.5.0\bin\i386\Rscript.exe" scripts\some_function.R
  Warning message:
  package 'data.table' was built under R version 3.5.1
  directory = W:/r/
  environment = dev
  Loading system parameters ...
  Loaded 32 parameters
  directory = W:/r/
  environment = dev
  Loading system parameters ...
  Loaded 32 parameters
  directory = W:/r/
  environment = dev
  Loading system parameters ...
  Loaded 32 parameters
  </code></pre>
  
  <p>What am I missing?</p>