title: Functions in R - using eval() and parse() to plot expressions in rgl
body: <p>I am very new to R. I am trying to create a function where the user is able to input expressions into arguments.  These inputs are then used in plot3d through the rgl package.  The function I have so far is :</p>
  
  <pre><code>flight_sim &lt;- function(xval, yval, zval)
  {
  # Evaluate arguments and convert them into expressions 
  eval(parse(text = zval))
  z &lt;- data.frame(zval)
  eval(parse(text = xval))
  x &lt;- data.frame(xval)
  eval(parse(text = yval))
  y &lt;- data.frame(yval)
  flight_path &lt;- as.data.frame(cbind(x,y,z))
  }
  </code></pre>
  
  <p>I have a readline() and switch() command :</p>
  
  <pre><code>cat('Select the flight path you wish to plot from the list below : 
  1. Helix
  2. Conical
  3. Spherical
  4. Define your own flight path...')
  
  userplot &lt;- readline('Enter number here : ') # Allow user to enter choice from above
  
  switch(userplot,"1"=flight_sim( sin(z), 1-cos(z), seq(0,20, pi/32) ),
                  "2"=flight_sim( z*cos(6*z), z*sin(6*z), seq(0,10, pi/64) ),
                  "3"=flight_sim( sin(z)*cos(20*z), sin(z)*sin(20*z), seq(0,pi,pi/399)), 
                  "4"=custom())
  </code></pre>
  
  <p>Where custom() just prompts the user via readline() to enter x, y and z values, which is then followed by eval() and parse() and it works fine.</p>
  
  <p>The problem I've been having is that x and y need to be functions of z, and this causes an error :</p>
  
  <pre><code>Error in parse(text = xval) : object 'z' not found
  </code></pre>
  
  <p>I thought by making the flight_sim function evaluate the zval argument first that it would fix it, however as I'm new to R I'm just getting more and more lost.  </p>
  
  <p>I hope what I have explained here makes some sense.  I appreciate any help that can be provided.</p>