title: Run a system command as sudo from R?
body: <p>Sometimes this works, sometimes not. It seems to depend on whether the system needs to prompt for a password. The more general question would be: is there a way for the user to provide input to a shell command from within R?</p>
  
  <pre><code>system('sudo npm install gitbook -g')
  </code></pre>
  
  <p>Note that my specific case is trying to install a node.js module. However, I think you can replicate it using a more trivial command.</p>
  
  <pre><code>system('sudo mkdir testdir')
  </code></pre>
  
  <p>Please note that this will sometimes work depending on whether <code>sudo</code> requires you to re-enter a password. Thanks.</p>