Skip to content
Prev 172073 / 398503 Next

call lm function in R

Hello everybody,

i have to make a c++ programm, which calls the function lm() in R. Therefore i installed the rcpp-package. There were some examples too. 

I tried something, but i have the problem with the SEXP structure:

I want to call lm() without coming from R:

class MyVectorFunc : public RcppFunction {
public:
	MyVectorFunc() : RcppFunction( new SEXP(mkChar( "lm" )) {}

	double 
	funtkionsaufrufer( vector<double>& v )
	{
		setRVector(v);
		SEXP result = vectorCall();
		double value = REAL(result)[0];
		clearProtectionStack();
		return value;
	}
	

};


RcppFunction is from the Rcpp-package and this needs a SEXP-parameter. How can i create lm() as a SEXP parameter.

I m very thankful for every answer.

Bye