2019-03-23使Jupyter Notebook与R连用

之前在学习python时,Jupyter Notebook一直是一个很好的工具,可以固定代码和结果。今天忽然想到是否可以使用这个软件与R一起使用,于是就找了一些资料,学习到了链接的方法。
但是可惜的是我在运行过程中遇到了一些问题,好像在Rstuido中无法完成链接操作,所以现在记录一下我解决的步骤,希望对大家有所帮助。我最后的技巧来源是stackoverflow。

  1. 安装好R
  2. 安装好Anaconda,以便使用其附带的Jupyter Notebook。
  3. 在R中先安装本次所需要的包,包的名称是IRkernel,在CRAN、github都可以下载。
install.packages('IRkernel')
IRkernel::installspec()  # to register the kernel in the current R installation

我遇到的问题是,运行IRkernel::installspec()时报错。后面参考了这里的解答。

One way to overcome the problem - if adding PATH variables to the environment doesn't work - is the following:
1.If Anaconda is installed and the Jupyter-Notebook with it (should be the standard install), open up the Anaconda prompt, not the Windows command prompt or the Anaconda Navigator
2.Look up the executable of R (not Rgui or Rstudio), it should be somewhere like C:\Program Files\R\R-3.5.1\bin and copy the path
Paste the path into the Anaconda prompt and start R by typing R
3.Now execute IRkernel::installspec() once again, this time there shouldn't be an error
Now you can start an R kernel within Jupyter-Notebook

  1. 运行Anaconda下的Anaconda Prompt。

5.输入代码

cd "C:\Program Files\R\R-3.5.1\bin" 
#这是你R安装的地址,取决于你自己的电脑情况
IRkernel::installspec() 
#链接操作

这样操作之后,再打开Jupyter Notebook就可以运行R的脚本了。

你可能感兴趣的:(2019-03-23使Jupyter Notebook与R连用)