Chapter 7. Using R and Python in Julia

I recently faced an efficiency challenge in my data analysis pipeline: Python and R were too slow, even with parallelization. To address this, I began learning Julia.

Surprisingly, I discovered a method to integrate all major data analysis languages in a single notebook. Now we can seamlessly combine machine learning (in Python), fast data preparation (using Julia), and result visualization with ggplot2 (supported in R).

Prerequisites

  • Python, R, Julia installed

  • Jupyter Notebook installed

  • Install Julia kernel:

    • Enter Julia REPL

    • For example, we want to add a Julia kernel in Jupyter using multi-threads: installkernel("Julia (4 threads)", env=Dict("JULIA_NUM_THREADS"=>"4"))

  • Install PyCall and RCall in Julia

import Pkg; Pkg.add("RCall"); Pkg.add("PyCall")

# Import libraries
using RCall, PyCall, DataFrames
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.11/Project.toml`
  No Changes to `~/.julia/environments/v1.11/Manifest.toml`
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.11/Project.toml`
  No Changes to `~/.julia/environments/v1.11/Manifest.toml`

Using R in Julia

1. Using R-functions:

2. Using R codes:

png

Using Python in Julia

1. Using Python functions

2. Using Python code blocks

Alternatives

  • 2Sigma, BeakerX, https://github.com/twosigma/beakerx

Last updated

Was this helpful?