Hi I think I have asked these questions earlier, but I been able to find answers from the documentation (which I found poorly written in several places). Will someone be kind enough to give me answers and enlighten me? (as in explain with CODE?)
I want to embed R in my application and use the fPortfolio package for carrying out risk management computations. Right now I'm reading the Rmetrics Ebook and trying to convert the various examples into embedded C code. Coming from a strictly C background, I have slight difficulty in comprehending a functional language like R and it gets worse when I try to embed R into a procedural language like C. So here is a list of my doubts: 1) I am very confused on how the lang 1 2 3 4 ... set of functions work. I haven't found any relevant documentation explaining it clearly. I have a vague idea but still I cannot understand how I would evaluate an R expression like Covariance <- round(cov(100 * SWX.RET), digits = 4) using lang, install and R_tryEval. 2) What exactly does install do? 3) I wrote the following code: #include <Rinternals.h> #include <Rembedded.h> int main (int argc, char** argv) { SEXP e,val; int errorOccurred; Rf_initEmbeddedR(argc, argv); // library("fPortfolio") PROTECT(e = lang2(install("library"), mkString("fPortfolio"))); R_tryEval(e, R_GlobalEnv, NULL); UNPROTECT(1); // colMeans(SWX.RET) PROTECT(e = lang2(install("colMeans"), install("SWX.RET"))); val = (R_tryEval(e, NULL, &errorOccurred)); Rf_PrintValue(val); return 0; } When I tried : >mean(SWX.RET) in the R prompt I got the following output: SBI SPI SII LP25 LP40 LP60 4.660521e-06 2.153198e-04 2.033869e-04 1.388886e-04 1.349041e-04 1.226859e-04 However when I replaced colMeans with mean in the C code above I got a mean of the means (0.0001366410) of all the columns when Rf_PrintValue was called. Using colMeans gave me the output as shown above. Why does this happen? How do I get the above output using mean? 4) From the above code segment, how can I deal with the SEXPREC val which is returned by R_tryEval in the above code and convert it to my own local vector datatype? How do I access the values of val? val will now be a timeseries so how do i convert it? Thanks Abhijit Bera [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel