From statmobile at gmail.com  Sat Nov 17 01:32:49 2007
From: statmobile at gmail.com (statmobile at gmail.com)
Date: Fri, 16 Nov 2007 19:32:49 -0500
Subject: [Rd] Returning vectors of two different data types back to
	R	environment (from C).
In-Reply-To: <8adccabf0711161249n763c3290o1ec4bab4bea1a104@mail.gmail.com>
References: <8adccabf0711161249n763c3290o1ec4bab4bea1a104@mail.gmail.com>
Message-ID: <20071117003249.GA10518@bjl>

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:

http://rgonzui.nakama.ne.jp/

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

Good Luck



[Rd] Returning vectors of two different data types back to R environment (from C).
statmobile at gmail.com