Evaluate an arbitrary symbolic expression given as a string at some values
<p>I would like to let a user enter a string, for a formula for <code>y</code> as a function of <code>x</code>, e.g.</p>

<pre><code>fn &lt;- "x^2 + exp(3*x)"
</code></pre>

<p>I would then like to evaluate this expression at some points, e.g. for values of <code>x &lt;- 1:0.1:100</code>.</p>

<p>I know I can do:</p>

<pre><code>x &lt;- 1:0.1:100
y &lt;- eval(parse(text = fn))
</code></pre>

<p>However, this leaves my computer open to attacks if the user supplies <code>fn</code> which is not a formula </p>

<pre><code>fn &lt;- 'x; print("Your computer is compromised")'
</code></pre>

<p>Are there any alternative ways of achieving what I want to do?</p>