Reputation: 5127
I am trying to run a tutorial for prophet, which uses R magic in a Jupyter notebook. The following code:
%%R
library(prophet)
df <- read.csv('../examples/example_wp_peyton_manning.csv')
df$y <- log(df$y)
m <- prophet(df)
future <- make_future_dataframe(m, periods=366)
Returns this:
Error in library(prophet) : there is no package called ‘prophet’
Then, in my iPython notebook I run this:
from rpy2.robjects.packages import importr
utils = importr('utils')
utils.install_packages('prophet')
Which returns this:
--- Please select a CRAN mirror for use in this session ---
Secure CRAN mirrors
1: 0-Cloud [https] 2: Australia (Canberra) [https]
3: Australia (Melbourne) [https] 4: Australia (Perth) [https]
5: Austria [https] 6: Belgium (Ghent) [https]
7: Brazil (RJ) [https] 8: Brazil (SP 1) [https]
9: Bulgaria [https] 10: Chile 1 [https]
11: China (Lanzhou) [https] 12: Colombia (Cali) [https]
13: Czech Republic [https] 14: Denmark [https]
15: France (Lyon 1) [https] 16: France (Lyon 2) [https]
17: France (Marseille) [https] 18: France (Montpellier) [https]
19: France (Paris 2) [https] 20: Germany (Münster) [https]
21: Iceland [https] 22: Indonesia (Jakarta) [https]
23: Ireland [https] 24: Italy (Padua) [https]
25: Japan (Tokyo) [https] 26: Malaysia [https]
27: Mexico (Mexico City) [https] 28: Norway [https]
29: Philippines [https] 30: Russia (Moscow) [https]
31: Spain (A Coruña) [https] 32: Spain (Madrid) [https]
33: Sweden [https] 34: Switzerland [https]
35: UK (Bristol) [https] 36: UK (Cambridge) [https]
37: UK (London 1) [https] 38: USA (CA 1) [https]
39: USA (KS) [https] 40: USA (MI 1) [https]
41: USA (TN) [https] 42: USA (TX 1) [https]
43: USA (TX 2) [https] 44: (other mirrors)
An input box show up and any selection I make leads to this:
rpy2.rinterface.NULL
I have RStudio, and prophet is up an running w/o problems in R Studio. This is telling me that I have another R kernel running somewhere, linked to the environment in Anaconda, or some other configuration error.
Is there any way to fix this issue so I can run R with the kernel I have in R Studio or force the current R kernel to install prophet?
How do I know the location of the R kernel used by R magic in this Jupyter notebook?
I am using a mac, and I might have some cross-linked files, etc. (My Jupyter notebook shows 6 kernels, when I really have 3..it is repeating what I have twice).
Thanks
Upvotes: 2
Views: 1460
Reputation: 547
You probably have 2 version of R. When you install R kernel from Anaconda, it installs its own version, regardless of what you have in in RStudio. This is what you should do. From a Jupyter notebook, run the following in a cell:
%load_ext rpy2.ipython
Then
%%R
.libPaths()
It should return something like this:
[1] "/Users/user/anaconda/lib/R/library"
Now go to RStudio and run the same line:
.libPaths()
It probably returns something like this:
[1] "/Users/user/Library/R/3.2/library"
[2] "/Library/Frameworks/R.framework/Versions/3.2/Resources/library"
In this example, you can see that one R is in anaconda, and the other one is a stand alone R. The one in your RStudio, the one where you correctly loaded Prophet is the standalone.
The best solution is to have RStudio use the same version that Conda is using. To do that, there are many ways to switch between the two versions, but the best one is to use a simple utility called Rswitch that you can download from here.
RSwitch detects all the versions of R that you have in you computer, and allows your RStudio to switch among the different version of R that you have.
Again, my suggestion is to switch to the version of R that Conda is using, and from RStudio, install your packages to avoid doing it from an Jupyter notebook, which can show errors such as the
rpy2.rinterface.NULL
that you indicated. Hope this works.
Upvotes: 1
Reputation: 11543
Many questions in the question. Answering one of them:
How do I know the location of the R kernel used by R magic in this Jupyter notebook?
In Jupyter, do:
%run -m rpy2.situation
Upvotes: 0