Skip to content
Prev 2017 / 10988 Next

[Rcpp-devel] error while calling function in loop

RInside R(argc, argv); //this would appear to be a class called RInside
definining a variable called R initialized with argc and argv variables.

To declare it globally, you would need to define it inside a *.cpp file
once, and only once. Usually this is easiest to do at the top of a *.cpp
file that uses it. Then do the same thing in other files that use it, but in
those cases, place the term "extern" in front of the declaration.

Example:

RInside R; //this is a declaration
extern RInside R; //this is a line for another file that lets the compiler
know it is declared in another *.cpp file.

Then inside your main function where you must be to get the argc and argv
variables, you could then initialize the class:
R=RInside(argc,argv);

I haven't ever used this class, and my instructions assume that a default
constructor for RInside is accessible to you. If it were not, then you would
have to make a pointer to it in the global scope and then assign it by
reference:

//outside of all {}'s at the top of a *.cpp file:
RInside *Rptr; //this is a pointer of type RInside declaration
extern RInside *Rptr; //this is a line for another file that lets the
compiler know Rptr is declared in another *.cpp file

//inside main
RInside R(argc, argv);
Rptr=&R;

I hope this helps,

Sean
On 3/26/11 10:18 AM, "Dirk Eddelbuettel" <edd at debian.org> wrote: