0

I am an avid python user. I have been programming and performing a lot of my statistics using R. Recently, I tried to go into one of my notebooks to perform some statistical analysis. I have written over 5000 lines of code. Now, I have used R functions scattered everywhere throughout my program. Unfortunately, I am unable to even use any of the functions i have written before.

This is what i have done before:

%load_ext rmagic
import rpy2.robjects as R
import pandas.rpy.common as com
from rpy2.robjects.packages import importr
import scipy.stats as sp
stats=importr('stats')
TSA = importr('TSA')
forecast = importr('forecast')
fUnitRoots = importr('fUnitRoots')
tseries = importr('tseries')
urca = importr('urca')
VARS = importr('vars')
zoo = importr('zoo')
aod = importr('aod')

Now, I can't even run any of this any more as i get an import error "r_magic extension has been moved".

Also, i have called R functions by doing the following:

%R acf(x)  

Above statement no longer works.

But if i do....

R.r('acf(x)')  

it works. This seems like an annoying change i have to incorporate in my large program. Is there a workaround towards this solution?

Thanks

4
  • 1
    What have you changed since the code stopped working? Commented Aug 6, 2015 at 15:23
  • my ipython notebook has upgraded to jupyter automatically. Ever since the change, nothing seems to work as before. I followed the example online on how to call R functions in python. It seems like the %R command doesn't work anymore in ipython. I have just went ahead with the online example and it works now. But now i have another issue which i am going to raise in the next question Commented Aug 6, 2015 at 16:33
  • This is the problem i am running into now: df = com.load_data('mtcars') rdf2 = com.convert_to_r_dataframe(df) robj.globalenv[ Commented Aug 6, 2015 at 16:39
  • This is the problem i am running into now: df = com.load_data('mtcars') rdf2 = com.convert_to_r_dataframe(df) robj.globalenv['rdf2'] = rdf2 robj.r('y=ts(rdf2)') fit_full = fGarch.garchFit('~1+garch(1,1),data=y,trace=F) For some reason, this gives me errors. "missing value where True/False needed Commented Aug 6, 2015 at 18:20

1 Answer 1

1

The rmagic is now in rpy2. Do: %load_ext rpy2.ipython

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.