Ich habe eine Funktion in RcppArmadillo Stil geschrieben und ich möchte es für das Ändern von Variablen in der aufrufenden Umgebung verwenden. Ich weiß, es ist nicht ratsam, solche Dinge zu tun, aber es ist in meinem Fall hilfreich. Konkret versuche ich das:Funktion übergeben durch Verweis in RcppArmadillo
#include <RcppArmadillo.h>
#include <iostream>
//[[Rcpp::export]]
void myfun(double &x){
arma::mat X = arma::randu<arma::mat>(5,5);
arma::mat Y = X.t()*X;
arma::mat R1 = chol(Y);
x = arma::det(R1);
std::cout << "Inside myfun: x = " << x << std::endl;
}
/*** R
x = 1.0 // initialize x
myfun(x) // update x to a new value calculated internally
x // return the new x; it should be different from 1
*/
Was vermisse ich? Warum funktioniert nicht?