<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body 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 class="Apple-style-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; orphans: 2; text-align: -webkit-left;
text-indent: 0px; text-transform: none; white-space: pre-wrap;
widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing:
0px; -webkit-border-vertical-spacing: 0px;
-webkit-text-decorations-in-effect: none;
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;
background-color: rgb(20, 20, 20); ">
<pre tabindex="0" class="GAKS5OJBBCB" id="rstudio_console_output" 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; -webkit-user-select: text; 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>
</body>
</html>