How to use R with Google Colaboratory?

吃可爱长大的小学妹 提交于 2019-11-26 18:10:46

问题


Google Colaboratory supports Python version 2.7 and 3.6

I see an example how to use Swift in Colab a while ago.

Today, I happened to run

!jupyter-kernelspec list

And found a new kernel: IRkernel

Available kernels:
  ir         /usr/local/share/jupyter/kernels/ir
  python2    /usr/local/share/jupyter/kernels/python2
  python3    /usr/local/share/jupyter/kernels/python3
  swift      /usr/local/share/jupyter/kernels/swift

Is it now possible to use R in Colab as well? No hassle in installing R kernel?


回答1:


Yes.

You can simply run the demo.ipynb from IRkernel Github.

Make changes and then save a copy to your Google Drive.

You can also see all 3 example notebooks here.




回答2:


In case you want to use Python and R together, you can use R magic for some cells.

# activate R magic
%load_ext rpy2.ipython

Then, whenever you want to use R, you begin the cell with %%R

%%R
x <- 42
print(x)

More details in rpy2 documentation



来源:https://stackoverflow.com/questions/54595285/how-to-use-r-with-google-colaboratory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!