Interoperability

In Quarto/R Markdown, {python} chunks share objects with R via r.

46.1 Python with reticulate

In Quarto/R Markdown, {python} chunks share objects with R via r. and py$. Positron and Jupyter support both languages side by side.

library(reticulate)
use_virtualenv("r-env")         # or use_condaenv(), or py_require() (uv-managed, recent versions)
np <- import("numpy")
np$mean(c(1, 2, 3))
py_run_string("x = [i**2 for i in range(5)]"); py$x
source_python("helpers.py")     # Python functions become R functions
r_to_py(mtcars); py_to_r(obj)

46.2 SQL, Julia, Stan, JavaScript, Java

SQL chunks in Quarto ({sql connection=con}), sqldf (SQL on data frames), duckdb.

JuliaCall, JuliaConnectoR.

cmdstanr / rstan for Stan models.

V8 (embedded JavaScript), htmlwidgets (wrap JS visualization libraries).

rJava (Java), RInside (embed R in C++), Rserve (R as a server), webR (R compiled to WebAssembly).

46.3 Calling R from other languages

rpy2 (Python), Rscript CLI, plumber APIs, opencpu.