Use R and Python together
This article provides procedures for running R in a Python notebook and running Python in an R notebook.
Run Python in a R Notebook with Reticulate
Open the Environment tool from the left-hand sidebar. You may need to start the machine to enable the environment management interface in this tool.
Use the search bar on the Explore tab to find Reticulate.
Click reticulate in the search results and click the Install button.
Confirm your action in the confirmation dialog and wait until the package is installed.
Restart the kernel after the package is installed.
Now, you can use Python in your R notebook. For example, you can create a pandas array as shown in the steps below.
- library(reticulate) py_install(packages = c("pandas"))
- pd <- import("pandas")
- pd$array(c(1, 2, 3))
Run R in a Python notebook
Open the Environment tool from the left-hand sidebar. You may need to start the machine to enable the environment management interface in this tool.
Click Edit init.sh to install additional dependencies. This will open the init.sh file in the file viewer on the right side of the editor.
In the init.sh file, add the following lines:
bash sudo apt-get update && \ DEBIAN_FRONTEND=noninteractive sudo apt-get install -y -q \ #### !!!! not sure about r-essentials --no-install-recommends r-essentials && \ Rscript -e "install.packages(c('ggplot2'), type = 'source')" && \ rm -rf /var/lib/apt/lists/* && \ apt-get clean pip install rpy2==3.5.1