RPweave: Unified R + Python + LaTeX System using uv
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
RPweave: Unified R + Python + LaTeX Document System
The Problem: Language Fragmentation in Research
As data scientists and researchers, we often find ourselves using three worlds:
- R for statistical analysis and beautiful visualizations (e.g ggplot2 or esgtoolkit)
- Python for machine learning and broader ecosystem (scikit-learn, PyTorch)
- LaTeX for professional typesetting and academic publishing
Traditionally (a long time ago, though), this meant maintaining separate scripts, manually copying results, and struggling with reproducible workflows.
There are existing solutions like R Markdown and Jupyter Notebooks,and Quarto, but none of them fully address my needs for reproducibility and environment management using any LaTeX template.
So, I hacked a workflow with RPweave – a unified document system that brings together the best of all worlds. It relies on:
- Knitr for R and Python code chunks
- Reticulate for Python integration in R
- LaTeX for high-quality typesetting
- uv for Python environment management
- Makefile/command line for automated builds (see below, as it’s especially designed for command-line use)
- Git template for version control (https://github.com/Techtonique/RPweave)
Getting Started
# 1. Use the GitHub template git clone https://github.com/Techtonique/RPweave my-paper cd my-paper # 2. Setup environments uv venv venv source venv/bin/activate make setup # 3. Start writing! make view
More on RPweave
Example document structure:
\documentclass{article}
\begin{document}
%mandatory Rnw setup
<<setup>>=
library(knitr)
library(reticulate)
use_python("venv/bin/python")
@
\section{R Analysis}
<<r-analysis>>=
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point()
@
\section{Python Analysis}
<<python-analysis, engine='python'>>=
import pandas as pd
df = pd.DataFrame({'x': range(100)})
print(df.describe())
@
\end{document}
Key Features
ENVIRONMENT MANAGEMENT
- Python: Managed by uv – the fast, modern Python package manager
- R: Simple, conditional package installation
- Isolated: Virtual environments for reproducible builds
SEAMLESS CROSS-LANGUAGE INTEGRATION
# R to Python data sharing r_data <- data.frame(x=1:10, y=rnorm(10)) py$shared_data <- r_data # Available in Python chunks!
PROFESSIONAL LATEX OUTPUT
- Academic-quality typesetting
- Automatic figure generation and placement
- Code syntax highlighting
- Bibliography support
WORKFLOW
# One-time setup ## create and activate Python virtual environment uv venv venv && source venv/bin/activate ## install R and Python dependencies make setup # Daily development make view # Build and open PDF after edits in main.Rnw
Project Structure
research-paper/ ├── main.Rnw # Your paper with embedded R/Python ├── chunks/ # Modular code organization ├── data/ # Research datasets ├── outputs/ # Generated figures ├── requirements.txt # Python dependencies └── Makefile # Automated build system
Real-World Use Case
Imagine writing a paper that needs:
- Complex statistical models (R: lme4, brms)
- Deep learning analysis (Python: PyTorch, TensorFlow)
- Professional formatting (LaTeX: equations, algorithms)
- Reproducible results (isolated environments)
With RPweave, you get all of this in a single, version-controlled document.
Pro Tips from Production Use
- Use
make viewas your primary writing command - it’s like “Save & Preview” - Organize long code in named
chunks/directory to keep main.Rnw clean - Version control everything except generated files (use
.gitignore) - R→Python data flow works seamlessly - structure analyses accordingly
The Expected Result for Me
- No more context switching between RStudio and Jupyter for LaTeX writing
- Integrated workflow that saves time and reduces errors
- Single source of truth for analysis and manuscript
- Professional output that meets academic standards
- Truly reproducible research with pinned dependencies (but don’t forget to
git commit)
Links & Resources
- RPweave GitHub Repository: https://github.com/Techtonique/RPweave
- UV Documentation: https://docs.astral.sh/uv/
- Knitr Documentation: https://yihui.org/knitr/

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.