-
-
Notifications
You must be signed in to change notification settings - Fork 8
Add dev container setup for R development environment #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # R Configuration for teal.code development | ||
|
|
||
| # Set up library paths | ||
| if (Sys.getenv("RSTUDIO") == "1" || file.exists("/.dockerenv")) { | ||
| # In dev container - use mounted volume for persistence | ||
| user_lib <- "/usr/local/lib/R/site-library" | ||
| } else { | ||
| # Local development - use user library | ||
| user_lib <- "~/R/library" | ||
| } | ||
|
Comment on lines
+4
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this compatible with Windows and Mac OSX? |
||
|
|
||
| # Ensure library directory exists | ||
| if (!dir.exists(user_lib)) { | ||
| dir.create(user_lib, recursive = TRUE, showWarnings = FALSE) | ||
| } | ||
|
|
||
| # Set library paths | ||
| .libPaths(c(user_lib, .libPaths())) | ||
|
|
||
| # Set CRAN mirror | ||
| options(repos = c(CRAN = "https://cran.rstudio.com/")) | ||
|
|
||
| # Set other useful options for development | ||
| options( | ||
| # Increase download timeout for large packages | ||
| timeout = 300, | ||
| # Use multiple cores for package installation | ||
| Ncpus = parallel::detectCores(), | ||
| # Better error handling | ||
| error = recover, | ||
| # Show warnings immediately | ||
| warn = 1 | ||
| ) | ||
|
|
||
| # Print library paths on startup | ||
| cat("R library paths:\n") | ||
| cat(paste(.libPaths(), collapse = "\n"), "\n\n") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Dev Container Setup for teal.code | ||
|
|
||
| This directory contains the development container configuration for the teal.code R package. | ||
|
|
||
| ## What gets installed automatically: | ||
|
|
||
| 1. **Base Environment**: Ubuntu 24.04 with R 4.3.3 (via rocker/verse image) | ||
| 2. **System Dependencies**: All required libraries for R package development | ||
| 3. **R Packages**: | ||
| - Core development packages: devtools, testthat, roxygen2, pkgdown, remotes, renv, usethis | ||
| - Project-specific packages: dplyr, random.cdisc.data, nestcolor | ||
| - Dependencies for teal.code package | ||
|
|
||
| ## Persistence: | ||
|
|
||
| - **R packages** are installed to `/usr/local/lib/R/site-library` which is mounted to `.devcontainer/r-packages/` on your host | ||
| - This means packages will persist between container rebuilds | ||
| - The first setup may take a few minutes, but subsequent starts will be faster | ||
|
|
||
| ## Usage: | ||
|
|
||
| 1. Open this repository in VS Code | ||
| 2. When prompted, click "Reopen in Container" or use Command Palette > "Dev Containers: Reopen in Container" | ||
| 3. Wait for the container to build and setup script to complete | ||
| 4. Start developing! | ||
|
|
||
| ## Customization: | ||
|
|
||
| - Modify `setup.sh` to add additional R packages or system dependencies | ||
| - Update `devcontainer.json` to change VS Code extensions or settings | ||
| - The `.Rprofile` is configured to work optimally with this setup | ||
|
|
||
| ## Troubleshooting: | ||
|
|
||
| If you encounter issues: | ||
| 1. Rebuild the container: Command Palette > "Dev Containers: Rebuild Container" | ||
| 2. Check the setup script logs in the terminal | ||
| 3. Ensure Docker has sufficient resources (4GB+ RAM recommended) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "name": "R Development Environment for teal.code", | ||
| "image": "rocker/verse:4.3.3", | ||
|
|
||
| "features": { | ||
| "ghcr.io/rocker-org/devcontainer-features/r-packages:1": { | ||
| "packages": "devtools,testthat,roxygen2,pkgdown,remotes,renv,usethis" | ||
| }, | ||
| "ghcr.io/devcontainers/features/git:1": { | ||
| "ppa": true, | ||
| "version": "latest" | ||
| } | ||
| }, | ||
|
|
||
| "postCreateCommand": "bash .devcontainer/setup.sh", | ||
|
|
||
| "customizations": { | ||
| "vscode": { | ||
| "extensions": [ | ||
| "REditorSupport.r", | ||
| "ms-vscode.vscode-json", | ||
| "ms-vscode.vscode-typescript-next", | ||
| "github.copilot" | ||
| ], | ||
| "settings": { | ||
| "r.rterm.linux": "/usr/local/bin/R", | ||
| "r.rpath.linux": "/usr/local/bin/R", | ||
| "r.bracketedPaste": true, | ||
| "r.plot.useHttpgd": true, | ||
| "r.sessionWatcher": true, | ||
| "r.rtermSendDelay": 8 | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| "mounts": [ | ||
| "source=${localWorkspaceFolder}/.devcontainer/r-packages,target=/usr/local/lib/R/site-library,type=bind,consistency=cached" | ||
| ], | ||
|
|
||
| "remoteUser": "rstudio" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # This file ensures the r-packages directory is preserved in git | ||
| # R packages will be installed here and persisted via dev container mount |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/bin/bash | ||
|
|
||
| # R Package Installation Script for teal.code development | ||
| set -e | ||
|
|
||
| echo "Setting up R environment for teal.code development..." | ||
|
|
||
| # Update package list | ||
| sudo apt-get update | ||
|
|
||
| # Install additional system dependencies if needed | ||
| sudo apt-get install -y \ | ||
| libcurl4-openssl-dev \ | ||
| libssl-dev \ | ||
| libxml2-dev \ | ||
| libgit2-dev \ | ||
| libharfbuzz-dev \ | ||
| libfribidi-dev \ | ||
| libfreetype6-dev \ | ||
| libpng-dev \ | ||
| libtiff5-dev \ | ||
| libjpeg-dev | ||
|
|
||
| # Install essential R packages | ||
| echo "Installing R packages..." | ||
| R -e " | ||
| # Set CRAN mirror | ||
| options(repos = c(CRAN = 'https://cran.rstudio.com/')) | ||
|
|
||
| # Install essential packages for development | ||
| install.packages(c( | ||
| 'devtools', | ||
| 'testthat', | ||
| 'roxygen2', | ||
| 'pkgdown', | ||
| 'remotes', | ||
| 'renv', | ||
| 'usethis', | ||
| 'dplyr', | ||
| 'random.cdisc.data', | ||
| 'nestcolor' | ||
| ), dependencies = TRUE) | ||
|
Comment on lines
+31
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
|
|
||
| # Try to install teal.data if available | ||
| tryCatch({ | ||
| install.packages('teal.data') | ||
| }, error = function(e) { | ||
| message('teal.data package not available from CRAN, will need to install from GitHub') | ||
| }) | ||
|
Comment on lines
+44
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why install |
||
| " | ||
|
|
||
| # Install the current package in development mode | ||
| echo "Installing teal.code package dependencies..." | ||
| R -e " | ||
| if (file.exists('DESCRIPTION')) { | ||
| devtools::install_deps(dependencies = TRUE) | ||
| } | ||
| " | ||
|
|
||
| echo "R environment setup completed!" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this enforces too many decisions on the developers and we shouldn't include
.Rprofileon the repos.This is unprecedented on the organization and tidyverse.
In pharmaverse it appears on
stdm.oak, but otherwise it's not used anywhere.