[R] How to call t.test() defined in t.test.R from C++ program

sfang@cs.concordia.ca sfang at cs.concordia.ca
Tue Jun 17 19:34:15 CEST 2003


Hi,

I am a student in Computer Science. Currently, I wrote a program (as pipeline) 
using STL(standard template library)in Visual C++ to analysis microarry gene 
express data analysis. 

Part of my program is to perform two sample t-test and print out t=? , df=? , p-
value=? , 95 percent confidence interval, and mean of each sample, which is the 
same output as typing the commands “library(ctest)” and “t.test(A, B)” under R. 
Therefore, I am wondering if I am able to call t.test() function from R in my 
C++ program.

I have read all .c, .R and .Rd files in the library(ctest). I know t.test.R 
proferms the functions which I want. but I could not figure out the 
relationship between .R and .c files. Therefore, I do not know if I should (and 
how to) call t.test() function defined in the file "t.test.R”,  or I should to 
call some functions defined in .c files (such as chisqsim(), but it require 
many parameters) and which one I should to call and how to call.

I have read the R manuals "Writing R Extensions", and I have tried to run some 
examples in 4.7 "Handling R objects in C", such as, out() function, .call
("out", a, b), but it seems not work. 

My code (save as try.cpp) is,

#include <R.h>
#include <Rinternals.h>
#include <iostream>
using namespace std;

int main()
{
  double sampleData_1[10]={1.1, -1.22, -2.1, 3.2, 4.5, 1.22, 0.55, -0.99, 1.77, 
2.33};
  double sampleData_2[8]={1.222, -0.999, -3.99, 2.77, 0.89, 0.99, 1.77, 0.78};
  .call("t.test", sampleData_1, sampleData_2);
  return 0;
}

I have tried to compile it under RedHat Linus by typing:

gcc -I/pkg/R/lib/R/include try.cpp -o outputfile

I got error message "parse error before ."


Since I am a newer for R, could someone please show me how to do? I really 
appreciate.

By the way, could someone please tell me the formulate to get p-value from 
t_value and the number of samples? I would like to try coding the calculation 
directly from C++ if I am unable to call t.test() function from R?

Thank you very much for your help,


Shaozhen




-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/




More information about the R-help mailing list