[Rcpp-devel] error while calling function in loop

Dirk Eddelbuettel edd at debian.org
Sat Mar 26 13:23:11 CET 2011


On 26 March 2011 at 14:59, nandan amar wrote:
| I have two version of following  code , calling the function copy() in
| loop gives error.
| I could not figure out why is it so?

Because you ignored the _requirement_ of having only one RInside instance per
program and you are creating a new one in each call to copy. Don't do
that but rather share one instance via a reference, pointer, global var, ...

Dirk

| -----------------------------------------------------------------------------------------------------------------------
| #include <R.h>
| #include <R_ext/Applic.h>
| #include <Rinternals.h>
| #include <RInside.h>
| using namespace std;
| void copy(int *sum,int argc, char *argv[])
| {
|     RInside R(argc, argv);
|     R.parseEvalQ("input<-c(1,2,3,4,5)");
|     vector<int> summ(5,0);
|     summ=R["input"];
|     for(int i=0;i<5;i++)sum[i]=summ[i];
|     return;
| }
| int main(int argc, char *argv[])
|     {
|     int sum[50];
| 
|     copy(sum,argc, argv);
| 
|     for(int i=0;i<5;i++)std::cout << "value at "<<i+1<<" : " << sum[i]
| << std::endl ;
|     return(0);
|     }
| --------------
| output
| value at 1 : 1
| value at 2 : 2
| value at 3 : 3
| value at 4 : 4
| value at 5 : 5
| 
| 
| --------------------------------------------------------------------------------------------------------------------------------
| #include <R.h>
| #include <R_ext/Applic.h>
| #include <Rinternals.h>
| #include <RInside.h>
| using namespace std;
| void copy(int *sum,int argc, char *argv[])
| {
| 	RInside R(argc, argv);
| 	R.parseEvalQ("input<-c(1,2,3,4,5)");
| 	vector<int> summ(5,0);
| 	summ=R["input"];
| 	for(int i=0;i<5;i++)sum[i]=summ[i];
| 	return;
| }
| int main(int argc, char *argv[])
| 	{
|         int sum[50];
| 
|        for(int i=0;i<5;i++)
|        copy(sum,argc, argv);
| 
| 	for(int i=0;i<5;i++)std::cout << "value at "<<i+1<<" : " << sum[i] <<
| std::endl ;
| 	return(0);
| 	}
| ----------------------------
| Error while running
| 
| Error in .Call("R_isMethodsDispatchOn", onOff, PACKAGE = "base") :
|   Incorrect number of arguments (2), expecting 1 for R_isMethodsDispatchOn
| terminate called after throwing an instance of 'Rcpp::binding_not_found'
|   what():  binding not found: '.AutoloadEnv'
| Aborted
| 
| --
| Amar Kumar Nandan
| Karnataka, India, 560100
| http://aknandan.co.nr
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list