diff --git a/.Rprofile b/.Rprofile new file mode 100644 index 000000000..3edd97567 --- /dev/null +++ b/.Rprofile @@ -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" +} + +# 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") diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 000000000..dafddcb2c --- /dev/null +++ b/.devcontainer/README.md @@ -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) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..0dc062256 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -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" +} diff --git a/.devcontainer/r-packages/.gitkeep b/.devcontainer/r-packages/.gitkeep new file mode 100644 index 000000000..3ca08a071 --- /dev/null +++ b/.devcontainer/r-packages/.gitkeep @@ -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 diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100755 index 000000000..f87a799ff --- /dev/null +++ b/.devcontainer/setup.sh @@ -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) + +# 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') +}) +" + +# 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!" diff --git a/.gitignore b/.gitignore index cf72c037b..9c7e132b4 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,9 @@ vignettes/*.R vignettes/*.html vignettes/*.md tests/testthat/Rplots.pdf -tests/testthat/_snaps/**/*.new.md -tests/testthat/_snaps/**/*.new.svg +tests/testthat/_snaps/**/*.new.md +tests/testthat/_snaps/**/*.new.svg + +# Dev container R packages (will be persistent via mount) +.devcontainer/r-packages/* +!.devcontainer/r-packages/.gitkeep