How can I return a struct array from a .Call to a function in a C shared library and subsequently use that array in R?
For example:
typedef struct{
int thing1;
int thing2;
float thing3;
float thing4;
char thing5;
//... many more things of various simple types
} MY_STRUCT;
SEXP R_Calls_Me(SEXP args) {
// Do stuff with args...
// Create arrayOfMyStructs as what type??
return arrayOfMyStructs;
}
What type is arrayOfMyStructs such that R can use it?
It seems like a common thing one would want to do, but I cannot find any examples of this in the documentation for writing R extensions.
Typically you create list (generic vector) with the components you want to return. In your case something like
It is also customary to assign names to the vector, e.g.:
Note that what you are describing is not an array but a structure. Arrays are typically much easier to pass as vectors.