Hi, I'd like to construct an R list object in C++, fill it with relevant data, and pass it to an R function which will return a different list object back. I have browsed through all the R manuals, and examples under tests/Embedding, but can't figure out the correct way. Below is my code snippet:
#include <Rinternals.h> // Rf_initEmbeddedR and other setups already performed SEXP arg, ret; // this actually creates a pairlist. I can't find any API that creates a list PROTECT(arg = allocList(3)); // I want the first element to be type integer, second double, and third a vector. INTEGER(arg)[0] = 1; // <- runtime exception: "INTEGER() can only be applied to a 'integer', not a 'pairlist' REAL(arg)[1] = 2.5; // control never reached here VECTOR_PTR(arg)[2] = allocVector(REALSXP, 4); REAL(VECTOR_PTR(arg)[2])[0] = 10.0; REAL(VECTOR_PTR(arg)[2])[1] = 11.0; REAL(VECTOR_PTR(arg)[2])[2] = 12.0; REAL(VECTOR_PTR(arg)[2])[3] = 13.0; PROTECT(call = lang2(install(entryPoint.c_str()), arg)); ret = R_tryEval(call, R_GlobalEnv, &errorOccurred); I'll be grateful if you can point me to any online docs/samples. Thanks in advance, Wayne _______________________________________________ This e-mail may contain information that is confidential, privileged or otherwise protected from disclosure. If you are not an intended recipient of this e-mail, do not duplicate or redistribute it by any means. Please delete it and any attachments and notify the sender that you have received it in error. Unless specifically indicated, this e-mail is not an offer to buy or sell or a solicitation to buy or sell any securities, investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Barclays. Any views or opinions presented are solely those of the author and do not necessarily represent those of Barclays. This e-mail is subject to terms available at the following link: www.barcap.com/emaildisclaimer. By messaging with Barclays you consent to the foregoing. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered offi! ce at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. _______________________________________________ [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel