CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

rMVPA is an R package for Multivoxel Pattern Analysis (MVPA) of neuroimaging data. It provides infrastructure for machine learning analyses on neuroimaging datasets, supporting both programmatic R usage and command-line interfaces.

Common Development Tasks

Building and Testing

# Install package locally
R CMD INSTALL .

# Run R CMD check
R CMD check .

# Run specific tests
Rscript -e "testthat::test_file('tests/testthat/test_mvpa_searchlight.R')"

# Run all tests
Rscript -e "testthat::test_local()"

# Build documentation
Rscript -e "devtools::document()"

# Build vignettes
Rscript -e "devtools::build_vignettes()"

# Install with dependencies
Rscript -e "devtools::install(dependencies = TRUE)"

Linting and Code Quality

# Run lintr (if available)
Rscript -e "lintr::lint_package()"

# Check code coverage
Rscript -e "covr::package_coverage()"

High-Level Architecture

Core Design Patterns

  1. S3 Object System: The package uses S3 classes extensively for model types (mvpa_model, rsa_model, contrast_rsa_model, etc.) with generic functions (train_model, predict_model, performance).

  2. Model Registry: All machine learning models are stored in the MVPAModels environment (R/classifiers.R). Models follow a standard interface:

  3. type: "Classification" or "Regression"
  4. library: Required packages
  5. parameters: Tunable hyperparameters
  6. grid: Function to generate parameter grids
  7. fit: Model training function
  8. predict: Prediction function
  9. prob: Probability estimation (for classification)

  10. Analysis Workflows: Two main analysis approaches:

  11. Regional: Analyzes specific brain regions (ROIs)
  12. Searchlight: Sliding sphere analysis across the brain

  13. Cross-validation Infrastructure: Custom cross-validation system in R/crossval.R supports various schemes (k-fold, blocked, bootstrap).

Key Components

Important Ongoing Work

Caret Removal: The package is undergoing a major refactoring to remove the caret dependency (see caret_removal_plan.md). Key changes: - Replacing caret::train with custom tuning loops using rsample and yardstick - Model loading now exclusively uses the internal MVPAModels registry - Performance metrics transitioning from caret to yardstick functions

Current branch remaining-codex-integration contains work-in-progress changes.

Command Line Scripts

The scripts/ directory contains CLI tools: - MVPA_Searchlight.R: Searchlight analysis - MVPA_Regional.R: Regional/ROI analysis - MVPA_Cluster.R: Cluster-based analysis - MVPA_Predict.R: Prediction on new data

Testing Infrastructure

Key Dependencies

Model Registry (MVPAModels)

The package uses a centralized model registry called MVPAModels (an environment in R/classifiers.R). All built-in models are registered here with a consistent structure:

Development Notes



bbuchsbaum/rMVPA documentation built on June 10, 2025, 8:23 p.m.