Can someone help me in coverting c++ code into R


HI community,
i need an urgent help, can someone please help me and convert this code which is in C++ language into R language

#include <iostream>
#include <cmath>               
#include <fstream>                
#include <string>                    

using namespace std;

int main(int argc, char *argv[])
      std::string protein;
          ifstream aa;"aa.txt");        //we are getting the data from the file (we assume that we have aa.txt file) 
       aa>>protein;                //the sequence should be in one letter code (uppercase letters)
 int ProtLength;                       //now we are getting protein length
   ProtLength = protein.length();
   char Asp = 'D';
   char Glu = 'E';
   char Cys = 'C';
   char Tyr = 'Y';
   char His = 'H';
   char Lys = 'K';
   char Arg = 'R';

int AspNumber = 0;
int GluNumber = 0;
int CysNumber = 0;
int TyrNumber = 0;
int HisNumber = 0;
int LysNumber = 0;
int ArgNumber = 0;

int i=0;

for ( i = 0; i <= protein.length() - 1; ++i)              //  we are looking for charged amino acids
              if (protein[i] == Asp)

              if (protein[i] == Glu)

              if (protein[i] == Cys)

              if (protein[i] == Tyr)

              if (protein[i] == His)

              if (protein[i] == Lys)

              if (protein[i] == Arg)

    double NQ = 0.0; //net charge in given pH
    double QN1=0;  //C-terminal charge
    double QN2=0;  //D charge
    double QN3=0;  //E charge
    double QN4=0;  //C charge
    double QN5=0;  //Y charge
    double QP1=0;  //H charge
    double QP2=0;  //NH2 charge
    double QP3=0;  //K charge
    double QP4=0;  //R charge
    double pH = 0.0;           

for(;;)                //the infinite loop

// we are using pK values form Wikipedia as they give quite good approximation
// if you want you can change it



  //if you want to see how the program works step by step uncomment below line
  //      cout<<"NQ="<<NQ<<"\tat pH ="<<pH<<"\ti:" <<i++<<endl;       

if (pH>=14.0)
   {                                                 //you should never see this message
  cout<<"Something is wrong - pH is higher than 14"<<endl;  //

if (NQ<=0)                            // if this condition is true we can stop calculate

 pH+=0.01;                            // if not increase pH

 ofstream outfile;                //we are writing results to outfile.txt"outfile.txt");           
   outfile << "Protein length: "<<ProtLength<<endl;
   outfile << "Number of Asp = "<<AspNumber<<endl;   
   outfile << "Number of Glu = "<<GluNumber<<endl; 
   outfile << "Number of Cys = "<<CysNumber<<endl; 
   outfile << "Number of Tyr = "<<TyrNumber<<endl; 
   outfile << "Number of His = "<<HisNumber<<endl;
   outfile << "Number of Lys = "<<LysNumber<<endl; 
   outfile << "Number of Arg = "<<ArgNumber<<endl;
   outfile << "Protein isoelectric point: "<<pH<<endl;
   cout << "Protein isoelectric point: "<<pH<<endl;

    return EXIT_SUCCESS;


You might want to take a look at the RCPP package, which aims to integrate the two (C++ and R):


Check out the Rcpp package (ah @mara beat me to the punch), you can call this function direct from R.

Here's a chapter from Advanced R with tips on how to do this. Advanced R: High performance functions with Rcpp


This c++ code doesn't look too complicated, you can probably offer someone $50 to convert it to R for you and you'll find people willing to help.