Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# R Configuration for teal.code development
Copy link
Contributor

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 .Rprofile on the repos.

This is unprecedented on the organization and tidyverse.

In pharmaverse it appears on stdm.oak, but otherwise it's not used anywhere.


# 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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")
38 changes: 38 additions & 0 deletions .devcontainer/README.md
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)
41 changes: 41 additions & 0 deletions .devcontainer/devcontainer.json
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"
}
2 changes: 2 additions & 0 deletions .devcontainer/r-packages/.gitkeep
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
60 changes: 60 additions & 0 deletions .devcontainer/setup.sh
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is nestcolor and random.cdisc.data really necessary?


# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why install teal.data with teal.code?

"

# 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!"
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading