title: How can I shut down Rserve gracefully?
body: <p>I have tried many options both in Mac and in Ubuntu.
  I read the Rserve documentation</p>
  
  <pre><code>http://rforge.net/Rserve/doc.html
  </code></pre>
  
  <p>and that for the Rserve and RSclient packages:</p>
  
  <p><a href="http://cran.r-project.org/web/packages/RSclient/RSclient.pdf" rel="noreferrer">http://cran.r-project.org/web/packages/RSclient/RSclient.pdf</a></p>
  
  <p><a href="http://cran.r-project.org/web/packages/Rserve/Rserve.pdf" rel="noreferrer">http://cran.r-project.org/web/packages/Rserve/Rserve.pdf</a></p>
  
  <p>I cannot figure out what is the correct workflow for opening/closing a connection within Rserve and for shutting down Rserve 'gracefully'.</p>
  
  <p>For example, in Ubuntu, I installed R from source with the ./config --enable-R-shlib (following the Rserve documentation) and also added the 'control enable' line in /etc/Rserve.conf.</p>
  
  <p>In an Ubuntu terminal:</p>
  
  <pre><code>library(Rserve)
  library(RSclient)
  Rserve()
  c&lt;-RS.connect()
  c ## this is an Rserve QAP1 connection
  
  ## Trying to shutdown the server
  RSshutdown(c) 
  Error in writeBin(as.integer....): invalid connection
  
  RS.server.shutdown(c)
  Error in RS.server.shutdown(c): command failed with satus code 0x4e: no control line present   (control commands disabled or server shutdown)
  </code></pre>
  
  <p>I can, however, CLOSE the connection:</p>
  
  <pre><code>RS.close(c)
  &gt;NULL
  c ## Closed Rserve connection
  </code></pre>
  
  <p>After closing the connection, I also tried the options (also tried with argument 'c', even though the connection is closed):</p>
  
  <pre><code>RS.server.shutdown()
  RSshutdown()
  </code></pre>
  
  <p>So, my questions are:</p>
  
  <p>1- How can I close Rserve gracefully?</p>
  
  <p>2- Can Rserve be used without RSclient? </p>
  
  <p>I also looked at </p>
  
  <p><a href="https://stackoverflow.com/questions/24004257/how-to-shutdown-rserve-running-in-debug">How to Shutdown Rserve(), running in DEBUG</a></p>
  
  <p>but the question refers to the debug mode and is also unresolved. (I don't have enough reputation to comment/ask whether the shutdown works in the non-debug mode).</p>
  
  <p>Also looked at:</p>
  
  <p><a href="https://stackoverflow.com/questions/15314880/how-to-connect-to-rserve-with-an-r-client">how to connect to Rserve with an R client</a></p>
  
  <p>Thanks so much!</p>