title: Can't pass a character string to require() in a function?
body: <p>So I recently came across an issue with a simple function I'm attempting to write to check if a package is available, and download it if not.</p>
  
  <p>However for some reason, when I pass a character string to require via a function it fails to recognise it (see simple example below)...</p>
  
  <p>This works...</p>
  
  <pre><code>    p.f &lt;- function(x) print(x)
      p.f("Hello")
     [1] "Hello"
  </code></pre>
  
  <p>As does this...</p>
  
  <pre><code>    (require("base"))
      [1] TRUE
  </code></pre>
  
  <p>But this doesn't...? </p>
  
  <pre><code>    p.f &lt;- function(x) (require(x))
      p.f("base")
      Loading required package: x
      [1] FALSE
      Warning message:
      In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
      there is no package called ‘x’
  </code></pre>
  
  <p>Why does it fail to recognise the character string instead of x?</p>