title: Passing DataTable over COM into R
body: <p>I am trying to pass data from SQL, to C#, then to an R server for data analysis then back to my web application; however, the COM interface that I am using does not allow complex data types to be passed between C# and R (no data tables). I have gotten it to work in the past by using the following code:</p>
  
  <pre><code>    int count = dataTable.Rows.Count;
      object[] y = new object[count];
      object[] x = new object[count];
  
      //R does not accept DataTables, so here we extract the data from
      //the table and pass it into 2 double arrays.
      for (int i = 0; i &lt; count; i++)
      {
          y[i] = Convert.ToDouble(dataTable.Rows[i][0]);
          x[i] = Convert.ToDouble(dataTable.Rows[i][1]);
      }
      //Instantiate R connection
      StatConnector r = new STATCONNECTORSRVLib.StatConnectorClass();
      r.Init("R");
      r.SetSymbol("y", y);  //Passes column y into R
      r.SetSymbol("x", x);  //Passes column x into R
  </code></pre>
  
  <p>My problem now arises because I am no longer limited to just doubles, anything coming out of the SQL Database is fair game (int, varchar, etc...), and that I am no longer calling just 2 columns of data (it can be however many the user specifies).</p>
  
  <p>How can I convert a datatable of dynamic size and dynamic data types into an array that would be safe to pass over into rcom?</p>