Skip to contents

Introduction

thoth simplifies containerization by automatically creating a Docker environment that matches your local R setup. This ensures your analysis can be reproduced exactly as intended, regardless of where it runs.

Automatic Setup

When creating a new project, thoth handles Docker configuration automatically:

library(thoth)

create_analytics_project(
  "my_analysis",
  use_docker = TRUE
)

This creates two key files:

1. Dockerfile

FROM rocker/rstudio:${R_VERSION}

# System dependencies
RUN apt-get update && apt-get install -y \
    python3-pip \
    && rm -rf /var/lib/apt/lists/*

# Install DVC
RUN pip3 install dvc

# Project setup
WORKDIR /project
COPY . /project/

# R package installation
RUN R -e 'install.packages("renv")'
RUN R -e 'renv::restore()'

# Set permissions
RUN chown -R rstudio:rstudio /project

CMD ["/init"]

2. docker-compose.yml

services:
  rstudio:
    build: .
    ports:
      - "8787:8787"
    environment:
      - PASSWORD=rstudio
      - ROOT=TRUE
    volumes:
      - .:/project
    user: rstudio

Using the Environment

Starting RStudio Server

# Start the container
docker-compose up -d

# Access RStudio at http://localhost:8787
# Username: rstudio
# Password: rstudio

# Stop the container
docker-compose down

Key Features

1. Version Matching

  • Uses exactly the same R version as your local installation
  • Ensures perfect reproducibility across environments
  • Automatically handles system dependencies

2. Development Integration

  • Mounts your project directory
  • Real-time file synchronization
  • Preserves Git and DVC functionality

3. Package Management

  • Integrates with renv for dependency tracking
  • Automatically installs required packages
  • Maintains consistent package versions

Best Practices

Project Organization

  • Keep Docker files in version control
  • Document any customizations
  • Include Docker instructions in README

Development Workflow

# 1. Create project with Docker
create_analytics_project("analysis", use_docker = TRUE)

# 2. Start container
system("docker-compose up -d")

# 3. Develop in RStudio Server
# Access at http://localhost:8787

# 4. Track dependencies automatically
# renv and Docker handle the rest

Sharing

# Recipients only need to:
git clone <repository>
cd <repository>
docker-compose up -d

Customization

You can customize the Docker setup by modifying:

  1. Dockerfile: Add tools or system dependencies
# Add custom system packages
RUN apt-get update && apt-get install -y \
    your-package-here

# Add R packages
RUN R -e 'install.packages("your-package")'
  1. docker-compose.yml: Adjust container settings
services:
  rstudio:
    ports:
      - "custom-port:8787"
    environment:
      - CUSTOM_VAR=value

Next Steps