title: Make a R script executable by sourcing it in a batch file
body: <p>I made a GUI using RGtk2 named Main.R that works perfectly when run from RStudio but only works in CMD when I open R in it and then source the script. My goal is to make it fully portable and thus to write a .bat file able to run it.</p>
  
  <p>Classical commands <em>R CMD BATCH Main.R</em> and <em>Rscript Main.R</em> don't work. In these cases, instead of waiting for me to interact, <strong>the window is closed immediately after its creation.</strong> After some research I only found out that the OP from <a href="https://stackoverflow.com/questions/17811871/run-r-script-from-bat-batch-file">run R script from .bat (batch file)</a> (sadly unanswered) encountered a similar issue, but my question differs from his so I still believe my post is justified.</p>
  
  <p>These commands don't even work for a very simplistic program I made with the same library, which indicates that <strong>the issue may be caused by GTk itself.</strong></p>
  
  <pre><code>library(RGtk2)
  
  Destroy &lt;- function(button) {
    window $ destroy()
  }
  
  vbox &lt;- gtkVBoxNew (FALSE, 10, TRUE) #container for the first tab
  vbox $ setBorderWidth (10)
  
  label &lt;- gtkLabelNew ("Welcome ! Click on the button to close the window")
  vbox $ packStart (label, TRUE, 20, 0)
  
  closeButton &lt;- gtkButtonNewWithLabel("Close")
  vbox $ packStart(closeButton, FALSE, FALSE, 0)
  gSignalConnect (closeButton , "clicked" , Destroy)
  #links the startButton to the Start function
  
  window &lt;- gtkWindow (NULL, FALSE)
  window ["title"] &lt;- "Example"
  gtkWindowResize(window, 800, 450)
  window $ add (notebook)
  
  window $ showAll()
  </code></pre>
  
  <p>In my batch file, I tried this among other variants :</p>
  
  <pre><code>@echo off
  title OCR GUI
  start R.exe &amp; "source("OCR_MR/R/Main.R")"
  </code></pre>
  
  <p>But of course the file executes the last line when the R session is closed manually. As R.exe can't take any arguments <strong>I need to make my batch file make an input inside R.</strong> Is there any way to do it ?</p>
  
  <p>Any help will be highly appreciated !</p>
  
  <p><strong>UPDATE</strong> : Thanks to some comments I realised Rscript doesn't wait for any kind of input, even</p>
  
  <pre><code>readline(prompt="message")
  </code></pre>
  
  <p>doesn't work. It may be an issue of running interactive commands in a non-interactive mode, will keep you updated !</p>