I'm trying to get a reference to this object in C

SWX.RET[1:6,c("SBI,"SPI","SII")]

While i am able to access and use a plain SWX.RET object, I'm getting
confused on how to create an object with the array subscripts like above.

Here is what I tried to do. It doesn't work because "[" is obviously not an
operation or function on SWX.RET. So how do I get a reference to this
object?

#include <stdio.h>
#include <R.h>
#include <Rinternals.h>
#include <Rdefines.h>
#include <Rembedded.h>

int main(int argc, char** argv)
{

    SEXP e,c,portSpec,portData,portConstr,portVal,tsAssets;
    int errorOccurred,nx,ny,i,j;
    double *v;
    const char *x,*y;

    Rf_initEmbeddedR(argc, argv);

    // loading fPortfolio
    PROTECT(e = lang2(install("library"), mkString("fPortfolio")));
    R_tryEval(e, R_GlobalEnv, NULL);
    UNPROTECT(1);


    // creating a default portfolioSpec object
    PROTECT(e=lang1(install("portfolioSpec")));
    PROTECT(portSpec=R_tryEval(e,R_GlobalEnv, NULL));

    // creating a portfolioData object


PROTECT(e=lang4(install("c"),mkString("SBI"),mkString("SPI"),mkString("SII")));
    PROTECT(c=R_tryEval(e,R_GlobalEnv,NULL));

    PROTECT(e=lang3(install("["),install("SWX.RET"),c));
    PROTECT(portData=R_tryEval(e,R_GlobalEnv,NULL));

    PROTECT(e=lang2(install("print"),portData));
    R_tryEval(e,R_GlobalEnv,NULL);


    UNPROTECT(3);

    Rf_endEmbeddedR(0);

    return 0;
}

	[[alternative HTML version deleted]]

