complex values in C

"Therneau, Terry M., Ph.D. via R-help" <[email protected]> Fri, 13 Mar 2026 21:25:01 -0500
Newsgroups gmane.comp.lang.r.general
Message-ID <[email protected]>
I've often used the following paradym in C code to define a list object returned to R

     static const char *outnames[]= {"dvec", "A", "Ainv",  "P", ""};
     SEXP rval, stemp;
     double *dvec, *A, *Ainv;
     int *P;


     PROTECT(rval = mkNamed(VECSXP, outnames));
     stemp=  SET_VECTOR_ELT(rval, 0, allocVector(REALSXP, nc));
     dvec= REAL(stemp);
     stemp = SET_VECTOR_ELT(rval, 1, allocMatrix(REALSXP, nc, nc));
     A = REAL(stemp);

Then the code puts values into dvec[i] and etc. and finally returns rval.

I'm missing how to do this when returning a complex value.   I've looked through the 
"Writing R extension" manual and have come up dry.  What am I missing?

Terry T.


-- 
Terry M Therneau, PhD
Department of Quantitative Health Sciences
Mayo Clinic
[email protected]

"TERR-ree THUR-noh"

	[[alternative HTML version deleted]]