title: Converting a character type to a logical
body: <p>I'm trying to create some code that is very user friendly to someone not that familiar with R.  The code is designed so that the logical criteria can easily be manipulated, based on what the user is looking for.  So instead of forcing the user to work within the if statements, I would like to just create a character variable containing the logical statement at the top of the code (i.e. <code>x &lt;- "a &gt; 2"</code>).</p>
  
  <p>Then I would like to evaluate an if statement using that character variable containing a logical operator.  Here is the basic idea:</p>
  
  <pre><code>a &lt;- 3
  x &lt;- "a &gt; 2"
  if(x)TRUE
  </code></pre>
  
  <p>This obviously returns an error that the argument is not interpretable as logical, because it sees x as the character string "a > 2."</p>
  
  <p>I know I could simply do:</p>
  
  <pre><code>a &lt;- 3
  x &lt;- as.logical(a &gt; 2)
  if(x)TRUE
  </code></pre>
  
  <p>However, in the case of what I'm working on, it would be preferable to initially store these logical statements as characters.  And as.logical() does not seem to be able to convert characters (i.e. <code>as.logical("a &gt; 2")</code>) does not work.</p>
  
  <p>My question: Is there some function I can put x through that allows R to view it not as a character, but rather as a logical statement?  In other words, how can I just strip away the quotation marks so that the logical statement can work inside an if statement?</p>