Note that there are some explanatory texts on larger screens.

plurals
  1. POrpy2/Rmagic: can't read csv data file
    primarykey
    data
    text
    <p>I have a pretty standard csv data set that I'm trying to read in IPython Notebook using rpy2/Rmagic:</p> <pre><code># R code %load_ext rmagic %R my.data &lt;- read.csv("/Users/xxx/Documents/data.csv") </code></pre> <p>I get this error:</p> <pre><code>--------------------------------------------------------------------------- TypeError Traceback (most recent call last) &lt;ipython-input-31-844400cf68c6&gt; in &lt;module&gt;() 25 ####Chunk 1: Inputting and checking the data ---&gt; 27 get_ipython().magic(u'R my.data &lt;- read.csv("/Users/xxx/Documents/data.csv")') 28 get_ipython().magic(u'R summary(my.data)') /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s) 2162 magic_name, _, magic_arg_s = arg_s.partition(' ') 2163 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) -&gt; 2164 return self.run_line_magic(magic_name, magic_arg_s) 2165 2166 #------------------------------------------------------------------------- /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line) 2088 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals 2089 with self.builtin_trap: -&gt; 2090 result = fn(*args,**kwargs) 2091 return result 2092 /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/IPython/extensions/rmagic.pyc in R(self, line, cell, local_ns) /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/IPython/core/magic.pyc in &lt;lambda&gt;(f, *a, **k) 189 # but it's overkill for just that one bit of state. 190 def magic_deco(arg): --&gt; 191 call = lambda f, *a, **k: f(*a, **k) 192 193 if callable(arg): /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/IPython/extensions/rmagic.pyc in R(self, line, cell, local_ns) 579 if return_output and not args.noreturn: 580 if result != ri.NULL: --&gt; 581 return self.Rconverter(result, dataframe=False) 582 583 __doc__ = __doc__.format( /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/IPython/extensions/rmagic.pyc in Rconverter(Robj, dataframe) 113 return np.asarray(Robj) 114 Robj = np.rec.fromarrays(Robj, names = names) --&gt; 115 return np.asarray(Robj) 116 117 @magics_class /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numpy/core/numeric.py in asarray(a, dtype, order) 233 234 """ --&gt; 235 return array(a, dtype, copy=False, order=order) 236 237 def asanyarray(a, dtype=None, order=None): TypeError: __float__ returned non-float (type rpy2.rinterface.NAIntegerType) </code></pre> <p>I'm guessing this has something to do with NA values in my csv data. I don't actually put a value there - just a blank entry (e.g. 1,,3,4).</p> <p>I tried replacing the blank entries with NA, a space, 0, etc. -- I always get the same error. What am I doing wrong?</p> <p><strong>Edit:</strong> I tried doing it with pure rpy2 (without making any changes to my data set):</p> <pre><code>import rpy2.robjects as robjects myData = robjects.r['read.csv']("/Users/xxx/Documents/data.csv") print robjects.r['summary'](myData) </code></pre> <p>and it works fine! So this must be something with IPython/Rmagic.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload