Datalore 2024.4 Help

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

  1. 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.

    Environment tool
  2. Use the search bar on the Explore tab to find Reticulate.

    Finding Reticulate
  3. Click reticulate in the search results and click the Install button.

    Installing Reticulate
  4. Confirm your action in the confirmation dialog and wait until the package is installed.

  5. 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.

  1. library(reticulate) py_install(packages = c("pandas"))
  2. pd <- import("pandas")
  3. pd$array(c(1, 2, 3))

Run R in a Python notebook

  1. 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.

    Environment tool
  2. 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.

  3. 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
Last modified: 08 November 2024