title: Passing identically named arguments through nested functions
body: <p>I am creating a simple plot which uses a plotting function, which calls another plotting function to add a smoothed line through it. The second function is <code>lines()</code> and takes some standard base graphics arguments. The first function also uses the same named argument. Now I would like to change some elements of the second plot without altering the first. I have at least a few options I can think of:</p>
  
  <ul>
  <li>Plot each seperately</li>
  <li>Rewrite the function to include uniquely named arguments to the second plotting function</li>
  <li>Make a new plot function for this maybe using ggplot2  </li>
  </ul>
  
  <p>And I got to thinking is it possible without rewriting anything, to pass through argument values to nested functions. Note in this question I am not asking for a function to do the plotting - I can write my own as necessry, I am asking if it is possible for me to specify in the arguments list to <code>traceplot</code> an argument that will only be passed to <code>lines</code> if it is also a named argument of traceplot. Example:</p>
  
  <pre><code>require(coda)
  require(geoRglm)
  
  # Some example data
  mcmc &lt;- c(0, 0, 0, 0, 0.5, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 
  0.5, 1, 0.5, 0, 0.5, 0.5, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 
  0, 0.5, 0.5, 0, 0.5, 1, 0, 0.5, 1, 0.5, 0.5, 0.5, 0, 0.5, 0.5, 
  0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, 0.5, 0, 0, 0, 
  0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0.5, 1, 1, 0, 1, 0, 
  0, 0.5, 0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0.5, 0.5, 0.5, 0, 1, 0.5, 
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 
  1.5, 1, 1.5, 1, 1, 1, 1, 0.5, 0.5, 1, 1, 1.5, 1.5, 1.5, 1, 1.5, 
  1.5, 1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5, 1, 1.5, 1.5, 
  1, 1.5, 1.5, 1, 1, 1, 1, 1)
  
  # Input parameters for mcmc object
  input &lt;- structure(list(S.scale = 3.75e-05, Htrunc = "default", S.start = "default", 
      burn.in = 0, thin = 100, n.iter = 20000, phi.start = 0, phi.scale = 1), .Names = c("S.scale", 
  "Htrunc", "S.start", "burn.in", "thin", "n.iter", "phi.start", 
  "phi.scale"), class = "mcmc.geoRglm")
  
  
  # create mcmc object
  mcmc_obj &lt;- create.mcmc.coda( mcmc , mcmc.input = input )
  
  
  #Plot - smooth = TRUE draws the smooth line through the data
  traceplot( mcmc_obj , smooth = TRUE , main = "Default")
  
  
  # Changing the colour argument passes the same argument through to the lines function called to plot the smooth line
  traceplot( mcmc_obj , smooth = TRUE , col = 2 , main = "Change colour to red")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/f9pqK.jpg" alt="enter image description here"></p>
  
  <pre><code># In the source code of traceplot 'lines()' is called to plot the smooth line.
  # Can I specify a colour argument to be passed only to lines without altering
  # the function?
  # Excerpt from the source code of traceplot:
  
  function (x, smooth = FALSE, col = 1:6, type = "l", ylab = "", 
      ...) 
  {
  ... some code here then...
  if (smooth) {
              for (k in 1:nchain(x)) lines(lowess(xp, yp[, k]) 
          }
  } 
  </code></pre>