I have installed all the packages required for rpy2, I want to embed R code in the jupyter notebook to do the data visualization.
But there's not much luck so far in my case, please point out which part I did wrong. Hope for a solution.
# Import the libraries
import pandas as pd
import matplotlib.pyplot as plt
import rpy2
# Imports required from rpy2
from rpy2.robjects import pandas2ri
pandas2ri.activate()
%load_ext rpy2.ipython
SheetA = pd.read_csv('C:\\Users\\test\\SheetA.csv')
SheetA_header=['Grill Type', 'Pre-Heat Time (In Seconds)', 'Fuel Cost Per Meal ($)', 'Market Share (%)', 'Ease Of Use', 'Life Span (In Years)', 'Initial Investment ($)']
SheetA=pd.read_csv("C:\\Users\\test\\SheetA.csv", header=None, skiprows=1, names=SheetA_header)
SheetA = pd.DataFrame(SheetA)
%%R -i SheetA
library(ggplot2)
ggplot(SheetA)
D:\Anaconda\lib\site-packages\rpy2\ipython\rmagic.py in _(obj)
147 if 'data.frame' in obj.rclass:
148 # request to turn it to a pandas DataFrame
--> 149 res = converter.ri2py(obj)
150 else:
151 res = ro.sexpvector_to_ro(obj)
D:\Anaconda\lib\functools.py in wrapper(*args, **kw)
838 '1 positional argument')
839
--> 840 return dispatch(args[0].__class__)(*args, **kw)
841
842 funcname = getattr(func, '__name__', 'singledispatch function')
D:\Anaconda\lib\site-packages\rpy2\robjects\pandas2ri.py in ri2py_listvector(obj)
181 def ri2py_listvector(obj):
182 if 'data.frame' in obj.rclass:
--> 183 res = ri2py(DataFrame(obj))
184 else:
185 res = numpy2ri.ri2py(obj)
D:\Anaconda\lib\functools.py in wrapper(*args, **kw)
838 '1 positional argument')
839
--> 840 return dispatch(args[0].__class__)(*args, **kw)
841
842 funcname = getattr(func, '__name__', 'singledispatch function')
D:\Anaconda\lib\site-packages\rpy2\robjects\pandas2ri.py in ri2py_dataframe(obj)
188 @ri2py.register(DataFrame)
189 def ri2py_dataframe(obj):
--> 190 items = tuple((k, ri2py(v)) for k, v in obj.items())
191 res = PandasDataFrame.from_items(items)
192 return res
D:\Anaconda\lib\site-packages\rpy2\robjects\pandas2ri.py in <genexpr>(.0)
188 @ri2py.register(DataFrame)
189 def ri2py_dataframe(obj):
--> 190 items = tuple((k, ri2py(v)) for k, v in obj.items())
191 res = PandasDataFrame.from_items(items)
192 return res
D:\Anaconda\lib\functools.py in wrapper(*args, **kw)
838 '1 positional argument')
839
--> 840 return dispatch(args[0].__class__)(*args, **kw)
841
842 funcname = getattr(func, '__name__', 'singledispatch function')
D:\Anaconda\lib\site-packages\rpy2\robjects\pandas2ri.py in ri2py_vector(obj)
137 @ri2py.register(SexpVector)
138 def ri2py_vector(obj):
--> 139 res = numpy2ri.ri2py(obj)
140 return res
141
D:\Anaconda\lib\functools.py in wrapper(*args, **kw)
838 '1 positional argument')
839
--> 840 return dispatch(args[0].__class__)(*args, **kw)
841
842 funcname = getattr(func, '__name__', 'singledispatch function')
D:\Anaconda\lib\site-packages\rpy2\robjects\numpy2ri.py in ri2py_sexp(obj)
157 def ri2py_sexp(obj):
158 if (obj.typeof in _vectortypes) and (obj.typeof != VECSXP):
--> 159 res = numpy.asarray(obj)
160 else:
161 res = ro.default_converter.ri2py(obj)
D:\Anaconda\lib\site-packages\numpy\core\_asarray.py in asarray(a, dtype, order)
83
84 """
---> 85 return array(a, dtype, copy=False, order=order)
86
87
ValueError: Buffer for this type not yet supported.
There's must be something wrong when processing dataframe to rpy2, only a guess.