title: multiple Rstudio sessions following the use of the parallel package
body: <p>I've recently run into an issue when using Rstudio-Server that multiple sessions are spawned instead of a single session. In my case (see below) five sessions are created instead of one. This happens even after trying the normal solutions: deleting  <code>~/.rstudio</code>, clearing <code>.GlobalEnv</code>, and restarting R. Note, there is no spawning issue when using the R command prompt.</p>
  
  <p><a href="https://i.stack.imgur.com/gVaau.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gVaau.png" alt="processes"></a></p>
  
  <p>My belief about the source of this problem is that it is due to a prematurely terminated <code>mclapply</code>. Here are the relevant docs from the <code>parallel</code> package. (discovered after the fact)</p>
  
  <blockquote>
    <p>It is strongly discouraged to use these functions in GUI or embedded environments, because it leads to several processes sharing the same GUI which will likely cause chaos (and possibly crashes). Child processes should never use on-screen graphics devices.</p>
  </blockquote>
  
  <p>At least one other person has <a href="https://support.rstudio.com/hc/en-us/community/posts/201644883-Child-processes-from-parallel-execution-not-terminated" rel="nofollow noreferrer">had the same error as me</a> but there is no documented solution that I can find. As the warning has already been ignored, I would appreciate any pointers that can help me get untangled.</p>
  
  <p>Edit:
  I am still encountering the error but was able to catch the ephemeral script sourcing issue that I believe is causing this problem. Unfortunately, I don't know what other files are being sourced and therefore what settings need to be changed. Grrrrr.....
  <a href="https://i.stack.imgur.com/8rCsc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8rCsc.png" alt="enter image description here"></a></p>