Re: [Rd] Returning vectors of two different data types back to R environment (from C).

From: <>
Date: Fri, 16 Nov 2007 19:32:49 -0500

On Fri, Nov 16, 2007 at 03:49:09PM -0500, Charles Danko wrote:
> Hello,
> Quick question.
> I have written a C function - I would like to make it return two vectors to
> the R environment - one STRSXP vector, and one INTSXP vector. Is this
> possible/ easy to do using the API?
> I looked, but could not find the answer to this question in the "Writing R
> Extensions" guide.

Yes, it's really quite reasonable to do, although it's not documented in detail in the R-extensions manual. As stated earlier, this will only work with .Call and SEXP functions where you can handle R objects within C.

In Section 5.9 "Evaluating R expressions in C" it has an example using lists in C. Basically, lists are VECSXP objects so you can search for that in R-exts.

Also, I would recommend looking at 5.7.6 "Handling lists" and the function:

SEXP getListElement(SEXP list, char *str)

You should look for that, and then grep the source files for examples. If you don't have grep to search the files, then I would recommend the R gonzui site:

Personally, I found the source code for det() to be a useful example, you can search for that on R gonzui.

Good Luck mailing list Received on Sat 17 Nov 2007 - 00:37:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 17 Nov 2007 - 04:30:19 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.