# Import command gives different solution to equation than cut & paste

I would like to import values from a text file to run a notebook. The notebook works fine when I cut and paste in all the input values manually. Here is a working version. But when I import the same the values from a text file using the Import command I get vastly different outcomes (i.e. this mess).

To minimize possible errors I'm only trying to import the first of four requested input sections, so this post is only regarding the ratevector element. The other input values I cut & pasted by hand.

I cannot figure out why the solutions are different when I import the rate vector vs. cut and pasting the ratevector.

As background, the original notebook was written by Townsend et. al. 2012 and should only calculate 3 values: probability of resolution prcortree, probability of incorrect resolution princtree & the probability of a polytomy prpolytomy for a given dataset. Thank you for any help you can give! I hope I tagged this correctly.

• how is this different from this: mathematica.stackexchange.com/questions/76807/… ? – george2079 Mar 9 '15 at 16:46
• I incorporated the answer from that post (and changed how I import my data) and I still get the wrong solution after running the notebook. – PGilbert Mar 9 '15 at 16:52
• Can you do Import[filename,"Lines"] and post the first few lines? – george2079 Mar 9 '15 at 16:53
• In[1]:= ratevector = Import["~/uce1_rates_SMALL.txt", "Lines"] Out[1]= {"0.6951, 0, 0.6951, 1.4425, 0, 0, 1.5222, 0.6951, 4.3295, 4.3283"} – PGilbert Mar 9 '15 at 17:08
• Or did you want the first few lines after I evaluate the notebook? 1-0.5 Erfc[(0.707107 (-0.5+3.46945*10^-18 2.71828^(-2563.11 0.6951, 0, 0.6951, 1.4425, 0, 0, 1.5222, 0.6951, 4.3295, 4.3283)+8.13152*10^-20 2.71828^(-2520.76 0.6951, 0, 0.6951, 1.4425, 0, 0, 1.5222, 0.6951, 4.3295, 4.3283)-4.66207*10^-18 2.71828^(-2492.22 0.6951, 0, 0.6951, 1.4425, 0, 0, 1.5222, 0.6951, 4.3295, 4.3283)- – PGilbert Mar 9 '15 at 17:35

You might fix the garbage you are getting with ToExpression:

      ratevector = Import[file, "CSV"][[1]] // ToExpression


I'd consider that a bit of a hack and prefer to understand why you are getting strings in the first place though.

## edit

I think I figured out whats going on -- It seems if your file contains tabs, ie.

    0.6951,<tab>0,<tab>0.6951,<tab>1.4425


that fools the "CSV" import into thinking the items are strings.

This might do the trick:

    Import[filename, "Table","FieldSeparators" -> {"\t",","," "}][[1]]

• Wow. That hack worked impressively. Not sure what's going on under the hood, but if I can get the correct computation that's good enough for me at the moment. Many thanks& cheers! – PGilbert Mar 9 '15 at 18:10