<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Thanks, it works!<br>
    I'm not familiar with C++, is it necessary to always use such a
    function in C++ or is it because of R/C++ interface?<br>
    Thanks again for your help,<br>
    <br>
    Pierre<br>
    <br>
    Le 26/02/2015 16:30, Jeffrey Pollock a écrit :
    <blockquote
cite="mid:CAG992jJy2yRVAXa-USvjFqV4HeDMghgvMoPpQ_qPSeoLK6VD5g@mail.gmail.com"
      type="cite">
      <div dir="ltr">Perhaps use the clone() function?<br>
        <br>
        library(Rcpp)<br>
        <br>
        cppFunction("<br>
        NumericVector par_CMAtR(NumericVector vec_CMA) {<br>
            NumericVector out = clone(vec_CMA);<br>
            out[5] = exp(out[5]);<br>
            return out;<br>
        }<br>
        ")<br>
        <br>
        vec_C <- rep(1, 6)<br>
        par_CMAtR(vec_C)<br>
        print(vec_C)<br>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Thu, Feb 26, 2015 at 3:16 PM, Pierre
          GLOAGUEN <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:Pierre.Gloaguen@ifremer.fr" target="_blank">Pierre.Gloaguen@ifremer.fr</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000"> <br>
              Hello everybody,<br>
              <br>
              I have a very simple example<br>
              I have a vector vec_CMA which length is a multiple of 6. <br>
              I want to get the exact same vector, except the last
              element which is the exponential of the last element of
              vec_CMA<br>
              The code is the following<br>
              <br>
              //myfun.cpp<br>
              #include <Rcpp.h><br>
              using namespace Rcpp;<br>
              <br>
              // [[Rcpp::export]]<br>
              NumericVector par_CMAtR(NumericVector vec_CMA){<br>
                int K = (vec_CMA.size())/6;<br>
                NumericVector out(6*K);<br>
                out = vec_CMA;<br>
                out[6*K-1] = exp(vec_CMA[6*K-1]);<br>
                return out;<br>
              }<br>
              <br>
              I apply the function with the R code<br>
              sourceCpp("myfun.cpp")<br>
              vec_C <- rep(1,6)<br>
              par_CMAtR(vec_C)<br>
              [1] 1 1 1 1 1 2.718282<span
                style="border-collapse:separate;color:rgb(248,248,248);font-family:'DejaVu
                Sans
Mono';font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:15px;text-align:-webkit-left;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;background-color:rgb(20,20,20)">
                <pre style="font-family:'DejaVu Sans Mono';font-size:10pt!important;outline-style:none;outline-width:initial;outline-color:initial;border-top-style:none;border-right-style:none;border-bottom-style:none;border-left-style:none;border-width:initial;border-color:initial;white-space:pre-wrap!important;word-break:break-all;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;line-height:1.2">8</pre>
              </span>works fine. Except the vec_C is modified too!<br>
              vec_C<br>
              [1] 1 1 1 1 1 2.718282<br>
              <br>
              It's the first time I have this kind of problem. What is
              wrong in my code?<br>
              Thanks for your help,<br>
              <br>
              Pierre Gloaguen<br>
              <br>
            </div>
            <br>
            _______________________________________________<br>
            Rcpp-devel mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
            <a moz-do-not-send="true"
href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel"
              target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
  </body>
</html>