title: Passing package name as argument in R
body: <p>I see myself keep using the <code>install.package</code> function a lot especially when I have to try out someone else's code or run an example.</p>
  
  <p>I as writing a function that installs and loads a package. I tried the following but it did not work:</p>
  
  <pre><code>inp &lt;- function(PKG)
  {
    install.packages(deparse(substitute(PKG)))
    library(deparse(substitute(PKG)))
  }
  </code></pre>
  
  <p>When I typed <code>inp(data.table)</code>, it says</p>
  
  <pre><code>Error in library(deparse(substitute(PKG))) : 
    'package' must be of length 1
  </code></pre>
  
  <p>How do I pass library name as argument in this case?
  I will appreciate if someone can also direct me to information pertaining to passing any kind of object as argument to a function in <code>R</code>.</p>