How to use R with Google Colaboratory?

Yes.

For a new R-notebook, use this link. (shorthand is colab.to/r )

You can learn from IRkernel demos, e.g. demo.ipynb

Save a copy in your Google Drive, and make any changes you need.

2 more demos:

  • Display.ipynb shows how to display HTML, images.
  • Comm_Demo.ipynb shows how to communicate between R and JavaScript.

See more details in IRkernel Github.


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


Open this link in your browser to create a new notebook with R Kernel

https://colab.research.google.com/notebook#create=true&language=r