0

I did programming my method in c++ as function named "test.cc".The syntax of my program is;

./test input.fasta theta > output.txt

Where input.fasta is data file

>0 1000 0
100
>0 1000 1
100
>0 1000 2
101

Theta is numeric value range 2 to 10. The output stored in output.txt file.

For developing R package; First I complied it using following command.

R CMD SHLIB test.cc

that produced "test.dll" file. I load it in R by using following command;

dyn.load("test.dll")

I am trying to call test function, but it gives error while reading data;

.C("test", as.double(input.fasta), as.integer(theta))

I have no experience of using this command; Problem is that how I read input.fasta to .C() and write output to file.

I would be thankful if you provide some idea to deal with this problem.

statuser
  • 49
  • 1
  • 2
  • 8
  • That doesn’t look like a Fasta file. Furthermore, there’s a (rather fundamental) difference between a function and a program, so it’s hard to say how your function needs to be called, since you don’t show us the relevant code. – Konrad Rudolph Mar 29 '15 at 22:57
  • My program has only one function named test, and I also shared its syntax. Data file is variant of the standard Fasta format and it is working perfectly in command prompt, but I want use in R package. – statuser Mar 29 '15 at 23:01
  • Not a `R` user. but maybe you need to wrap your function in `extern "C" { }`-blocks. – a3f Mar 29 '15 at 23:03
  • Yes you're right! But how can I read the data? – statuser Mar 29 '15 at 23:06
  • @statuser It is highly relevant how the function actually looks, i.e. what data types it accepts and returns. In addition, you cannot just call arbitrary C functions from R, you need to use specific wrappers (e.g. Rcpp). – Konrad Rudolph Mar 29 '15 at 23:25
  • Structure of my C++ program is following; int main(int argc, char* argv[]){ switch (argc){ case 5:{ ifstream ifs(argv[1]); if(!ifs){ cerr << "could not open file: " << argv[1] << endl; exit(1); } float a; sscanf(argv[2], "%f",&a); //.... } – statuser Apr 09 '15 at 19:17
  • It means one argument is character type and other is float type. Output is integer as well. Thanks if you help me writing wrapper for this function. It would be great help. – statuser Apr 09 '15 at 19:19

0 Answers0