title: Installing R packages with bash script - responding to prompts
body: <p>At my job, the edge node server that accesses our cluster is re-instantiated every day. This means I have to clone our repo and install a bunch of R packages every morning. I wrote a bash script (using <a href="https://github.com/eddelbuettel/littler" rel="nofollow noreferrer">https://github.com/eddelbuettel/littler</a> to open R from the command line) to automate this and it works except for one hiccup.</p>
  
  <p>Bash calls:
      r install.R</p>
  
  <p>which opens an R session and calls the following command:</p>
  
  <pre><code>repos &lt;- "http://... [our CRAN equivalent]"
  install.packages("[package_name]",repos)
  </code></pre>
  
  <p>Now, normally, if I were entering this myself in R, I would get this as a response:</p>
  
  <pre><code>Installing package into ‘/usr/hdp/2.5.5.3-2/spark2/R/lib’ (as ‘lib’ is unspecified)
  Warning in install.packages("[name_of_package]", repos = "http://...") :
  
  'lib = "/usr/hdp/2.5.5.3-2/spark2/R/lib"' is not writable
  Would you like to use a personal library instead?  (y/n) 
  </code></pre>
  
  <p>And I would say 'y,' followed by another 'y' when it suggests a library to create. However, when I do this from the bash script, it just says the library is not writable and aborts. </p>
  
  <p>Two options I see here:
  1) <strong>I tell it which library to write the packages in.</strong> I've tried this, and while the packages did go there, they arrived empty. Nothing was actually downloaded from the repo.</p>
  
  <p>2) Somehow get the script to be able to pipe in the two affirmative responses I need in order to let R do its thing and create its own library. </p>
  
  <p>Any suggestions on either of these would be much appreciated!</p>