Skip to content

Commit 9792145

Browse files
committed
Add dev container setup for R development environment
- Add devcontainer.json with rocker/verse R 4.3.3 image - Configure automatic installation of essential R packages - Set up persistent R package storage via volume mount - Add setup script for system dependencies and R packages - Configure .Rprofile for optimal dev container experience - Add VS Code extensions and settings for R development - Update .gitignore to handle dev container artifacts This setup ensures R and all necessary packages persist between container rebuilds, providing a consistent development environment for the teal.code package.
1 parent cb36b37 commit 9792145

File tree

6 files changed

+184
-2
lines changed

6 files changed

+184
-2
lines changed

.Rprofile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# R Configuration for teal.code development
2+
3+
# Set up library paths
4+
if (Sys.getenv("RSTUDIO") == "1" || file.exists("/.dockerenv")) {
5+
# In dev container - use mounted volume for persistence
6+
user_lib <- "/usr/local/lib/R/site-library"
7+
} else {
8+
# Local development - use user library
9+
user_lib <- "~/R/library"
10+
}
11+
12+
# Ensure library directory exists
13+
if (!dir.exists(user_lib)) {
14+
dir.create(user_lib, recursive = TRUE, showWarnings = FALSE)
15+
}
16+
17+
# Set library paths
18+
.libPaths(c(user_lib, .libPaths()))
19+
20+
# Set CRAN mirror
21+
options(repos = c(CRAN = "https://cran.rstudio.com/"))
22+
23+
# Set other useful options for development
24+
options(
25+
# Increase download timeout for large packages
26+
timeout = 300,
27+
# Use multiple cores for package installation
28+
Ncpus = parallel::detectCores(),
29+
# Better error handling
30+
error = recover,
31+
# Show warnings immediately
32+
warn = 1
33+
)
34+
35+
# Print library paths on startup
36+
cat("R library paths:\n")
37+
cat(paste(.libPaths(), collapse = "\n"), "\n\n")

.devcontainer/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Dev Container Setup for teal.code
2+
3+
This directory contains the development container configuration for the teal.code R package.
4+
5+
## What gets installed automatically:
6+
7+
1. **Base Environment**: Ubuntu 24.04 with R 4.3.3 (via rocker/verse image)
8+
2. **System Dependencies**: All required libraries for R package development
9+
3. **R Packages**:
10+
- Core development packages: devtools, testthat, roxygen2, pkgdown, remotes, renv, usethis
11+
- Project-specific packages: dplyr, random.cdisc.data, nestcolor
12+
- Dependencies for teal.code package
13+
14+
## Persistence:
15+
16+
- **R packages** are installed to `/usr/local/lib/R/site-library` which is mounted to `.devcontainer/r-packages/` on your host
17+
- This means packages will persist between container rebuilds
18+
- The first setup may take a few minutes, but subsequent starts will be faster
19+
20+
## Usage:
21+
22+
1. Open this repository in VS Code
23+
2. When prompted, click "Reopen in Container" or use Command Palette > "Dev Containers: Reopen in Container"
24+
3. Wait for the container to build and setup script to complete
25+
4. Start developing!
26+
27+
## Customization:
28+
29+
- Modify `setup.sh` to add additional R packages or system dependencies
30+
- Update `devcontainer.json` to change VS Code extensions or settings
31+
- The `.Rprofile` is configured to work optimally with this setup
32+
33+
## Troubleshooting:
34+
35+
If you encounter issues:
36+
1. Rebuild the container: Command Palette > "Dev Containers: Rebuild Container"
37+
2. Check the setup script logs in the terminal
38+
3. Ensure Docker has sufficient resources (4GB+ RAM recommended)

.devcontainer/devcontainer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "R Development Environment for teal.code",
3+
"image": "rocker/verse:4.3.3",
4+
5+
"features": {
6+
"ghcr.io/rocker-org/devcontainer-features/r-packages:1": {
7+
"packages": "devtools,testthat,roxygen2,pkgdown,remotes,renv,usethis"
8+
},
9+
"ghcr.io/devcontainers/features/git:1": {
10+
"ppa": true,
11+
"version": "latest"
12+
}
13+
},
14+
15+
"postCreateCommand": "bash .devcontainer/setup.sh",
16+
17+
"customizations": {
18+
"vscode": {
19+
"extensions": [
20+
"REditorSupport.r",
21+
"ms-vscode.vscode-json",
22+
"ms-vscode.vscode-typescript-next",
23+
"github.copilot"
24+
],
25+
"settings": {
26+
"r.rterm.linux": "/usr/local/bin/R",
27+
"r.rpath.linux": "/usr/local/bin/R",
28+
"r.bracketedPaste": true,
29+
"r.plot.useHttpgd": true,
30+
"r.sessionWatcher": true,
31+
"r.rtermSendDelay": 8
32+
}
33+
}
34+
},
35+
36+
"mounts": [
37+
"source=${localWorkspaceFolder}/.devcontainer/r-packages,target=/usr/local/lib/R/site-library,type=bind,consistency=cached"
38+
],
39+
40+
"remoteUser": "rstudio"
41+
}

.devcontainer/r-packages/.gitkeep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file ensures the r-packages directory is preserved in git
2+
# R packages will be installed here and persisted via dev container mount

.devcontainer/setup.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
# R Package Installation Script for teal.code development
4+
set -e
5+
6+
echo "Setting up R environment for teal.code development..."
7+
8+
# Update package list
9+
sudo apt-get update
10+
11+
# Install additional system dependencies if needed
12+
sudo apt-get install -y \
13+
libcurl4-openssl-dev \
14+
libssl-dev \
15+
libxml2-dev \
16+
libgit2-dev \
17+
libharfbuzz-dev \
18+
libfribidi-dev \
19+
libfreetype6-dev \
20+
libpng-dev \
21+
libtiff5-dev \
22+
libjpeg-dev
23+
24+
# Install essential R packages
25+
echo "Installing R packages..."
26+
R -e "
27+
# Set CRAN mirror
28+
options(repos = c(CRAN = 'https://cran.rstudio.com/'))
29+
30+
# Install essential packages for development
31+
install.packages(c(
32+
'devtools',
33+
'testthat',
34+
'roxygen2',
35+
'pkgdown',
36+
'remotes',
37+
'renv',
38+
'usethis',
39+
'dplyr',
40+
'random.cdisc.data',
41+
'nestcolor'
42+
), dependencies = TRUE)
43+
44+
# Try to install teal.data if available
45+
tryCatch({
46+
install.packages('teal.data')
47+
}, error = function(e) {
48+
message('teal.data package not available from CRAN, will need to install from GitHub')
49+
})
50+
"
51+
52+
# Install the current package in development mode
53+
echo "Installing teal.code package dependencies..."
54+
R -e "
55+
if (file.exists('DESCRIPTION')) {
56+
devtools::install_deps(dependencies = TRUE)
57+
}
58+
"
59+
60+
echo "R environment setup completed!"

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@ vignettes/*.R
2828
vignettes/*.html
2929
vignettes/*.md
3030
tests/testthat/Rplots.pdf
31-
tests/testthat/_snaps/**/*.new.md
32-
tests/testthat/_snaps/**/*.new.svg
31+
tests/testthat/_snaps/**/*.new.md
32+
tests/testthat/_snaps/**/*.new.svg
33+
34+
# Dev container R packages (will be persistent via mount)
35+
.devcontainer/r-packages/*
36+
!.devcontainer/r-packages/.gitkeep

0 commit comments

Comments
 (0)