NU Statistical Computing Workshop
Apr 22, 2026
🐍 “LLMs Love Python” (Twist et al. 2026)
®️ AutoCodeBench performance (Chou et al. 2025, 6)
Use the reticulate R package
Since Feb 2025: uv Renaissance
Used by ~350 other packages (e.g., marginaleffects)
Using Python from R
Intro to reticulate
Example: sentence-level semantic similarity
Leveraging JAX, a high-performance Python library
Automatic differentiation
Example: sensitivity analysis for error propagation
reticulateA package to interact with Python from R
Manages Python packages and environments
Translates between R and Python objects
Everything happens in R. You write R code!
Commercial APIs
LLMs (Anthropic, OpenAI, Google)
OCR (Mistral)
Data download (Youtube, Google Maps)
Pre-trained models for image/video/text
Cutting-edge scientific computing
~250k citizen submissions to the CL constitutional process
Compare submissions with topics and text from the world’s constitutions
Wrangle data
Embed text using multilanguage encoder
Compute “semantic” similarities
1_embeddings.RreticulateThe package automatically handles loops, indexing, and other tricky parts
R lists do a lot: e.g., package.module.function() becomes package$model$function()
In my experience, LLMs are good for short Python-to-reticulate translations
A high-performance Python package/ecosystem
By Google: powers some of their ML/AI
Good CPU and GPU performance
Key features:
Just-in-time-compilation
Automatic vectorization
Automatic differentiation
Analytic differentiation
Numeric differentiation
Automatic differentiation
Under the hood: boil functions down to their elementary operations; use the chain rule.
In JAX: differentiate (pretty much) arbitrary functions, e.g., most things in numpy (ex: marginaleffects).
2_jax.R (part one)Examine the degree to which our assumptions affect our results
Often apply extreme pressure
Tools: differentiation, optimization
Minimize the quantity of interest, while respecting the pointwise error ranges
We have great algorithms for box-constrained optimization, e.g., L-BFGS-B (Byrd et al. 1995)
They require derivatives
Analytical differentiation is not always available (e.g., MLE)
Numerical differentiation is slow and prone to error
Solution: automatic differentiation!
2_jax.R (part two)We can integrate Python tidbits into R via reticulate
Good candidates for Python snippets: commercial APIs, pre-trained models, scientific computing
LLM translation often works, but infrastructure is an always-moving target