title: Rcpp: one function works on NumericVector, the other needs to treat it as scalar
body: <p>I have two functions written with Rcpp.</p>
  
  <p>The first function <code>f</code> takes a NumericVector as input and returns a NumericVector as output. But often, <code>f</code> is meant to be treated as a scalar function. When I call it from R, it doesn't matter, since R will treat any scalar as a vector anyways, so I don't have to bother about it. I can both use <code>f</code> as a scalar or a vector function, e.g. <code>f(1)</code> and <code>f(c(1,2,3,4)</code> both work. </p>
  
  <ol>
  <li>Question 1: Is this a bad idea? Should I make TWO separate functions, one scalar, and one vectorized? For example, is there some unwanted overhead when I call <code>f</code> from R using scalar input rather than a vector? </li>
  </ol>
  
  <p>The second function <code>g</code> needs to use <code>f</code> purely as a scalar function. This causes a problem because I need to call <code>f</code> from Rcpp when I am defining <code>g</code>.... now I can't use it as a scalar function by calling <code>f(x</code>) for some double x. </p>
  
  <p>I tried doing something like this from inside the definition of <code>g</code>:</p>
  
  <pre><code>NumericVector x = NumericVector::create(value); //create vector of length 1
  f(x) //use f(x) as scalar 
  </code></pre>
  
  <p>but timing the code took absurdly long (since the function <code>g</code> needs to perform the above operation many times).</p>
  
  <ol>
  <li>Question 2: Is there a way to more quickly treat <code>f</code> as a scalar function just like I would if I was in R? </li>
  </ol>
  
  <p>My current solution is to do what I asked in Queston 1: create another <code>f</code> function which is scalar, and then call THAT one from <code>g</code>, so that inside <code>g</code> we simply say </p>
  
  <pre><code>alternative_f(x) //use alternative f as scalar
  </code></pre>