title: Passing a vector or matrix from R to a C function using Rcpp without a local copy?
body: <p>Here's an illustration of what I am currently doing with two functions. </p>
  
  <p>In both cases I am creating a local copies: either an instance of <code>std::vector&lt;GLfloat&gt;</code> or of <code>std::vector&lt;GLdouble&gt;</code>.</p>
  
  <p>Isn't there a shortcut not involving copies, where I could go from <code>Rcpp::NumericMatrix</code> to <code>GLfloat *</code>/<code>GLdouble *</code> in a more direct way?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;Rcpp.h&gt;
  #include &lt;GLFW/glfw3.h&gt;
  using namespace Rcpp;
  
  //' @export
  // [[Rcpp::export("glLoadMatrixf")]]
  void gl_load_matrixf(Rcpp::NumericMatrix m) {
  
    std::vector&lt;GLfloat&gt; float_v = Rcpp::as&lt;std::vector&lt;GLfloat&gt; &gt;(m);
    const GLfloat * _float_v = &amp;float_v[0];
  
    glLoadMatrixf(_float_v);
  }
  
  //' @export
  // [[Rcpp::export("glLoadMatrixd")]]
  void gl_load_matrixd(Rcpp::NumericMatrix m) {
  
    std::vector&lt;GLdouble&gt; double_v = Rcpp::as&lt;std::vector&lt;GLdouble&gt; &gt;(m);
    const GLdouble * _double_v = &amp;double_v[0];
  
    glLoadMatrixd(_double_v);
  }
  </code></pre>