Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1763f6d
Refactor duplicated posterior extraction logic into reusable helpers …
Copilot Dec 8, 2025
bb5a3b6
Add consolidated model fitting test file to unify all JAGS fitting te…
Copilot Dec 9, 2025
e24efd1
Refactor test-model-averaging.R and test-summary-tables.R to use pref…
Copilot Dec 9, 2025
1a41993
Refactor test-summary-tables.R to use prefitted models with file-base…
Copilot Dec 10, 2025
83d06cc
update summary tables tests (#54)
FBartos Dec 10, 2025
e70b5d1
Refactor plot tests (#55)
FBartos Dec 10, 2025
c5ca9b4
improve coverage
FBartos Dec 10, 2025
c33db02
update coverage
FBartos Dec 11, 2025
b6eccbf
update coverage
FBartos Dec 11, 2025
3be3c40
update coverage
FBartos Dec 11, 2025
5a52ffd
update coverage
FBartos Dec 11, 2025
928c48e
update coverage
FBartos Dec 11, 2025
5a8c85f
improve coverage
FBartos Dec 17, 2025
ceb25b9
further test consolidation
FBartos Dec 18, 2025
fc5bda8
further refactoring
FBartos Dec 18, 2025
dfa28c3
Add support for default priors in JAGS_formula()
FBartos Dec 26, 2025
a07390b
Add automatic standardization of continuous predictors in JAGS_formul…
Copilot Dec 29, 2025
75a2bd4
Add log(intercept) attribute support to formula interface
FBartos Dec 29, 2025
db49e67
fix scaling with multiple formulas
FBartos Dec 29, 2025
5bfef4c
Handle log(intercept) scaling in formula models
FBartos Dec 30, 2025
4e8a476
Add advanced parameter filtering to summary tables
FBartos Dec 31, 2025
e2d2209
fix documentation
FBartos Dec 31, 2025
18ad3e9
Add custom quantile support and update column names
FBartos Dec 31, 2025
5056f47
Handle bias-related parameters in filter helpers
FBartos Jan 1, 2026
417acb5
fix cmd check notes
FBartos Jan 2, 2026
6007070
add test caching
FBartos Jan 4, 2026
506f219
as_mixed PET and PEESE individual plots
FBartos Jan 5, 2026
c0b2329
init changes for individual PET/weightfunction plots
FBartos Jan 5, 2026
c670dac
Improve PET-PEESE and bias parameter handling in plots
FBartos Jan 5, 2026
e73d311
fix single weightfunction parameter plots
FBartos Jan 9, 2026
3ac50d9
fix plots
FBartos Jan 10, 2026
9282eb0
prep test
FBartos Jan 10, 2026
7294a64
update plotting + skills
FBartos Jan 10, 2026
e3d974d
improve default
FBartos Jan 11, 2026
1f64fdc
Add effect_direction argument to PET-PEESE plotting functions
FBartos Jan 13, 2026
25d28cd
transformation progress
FBartos Jan 14, 2026
236338e
follow: `plan-transform-scaled-plot-posterior.md`
FBartos Jan 30, 2026
03a38f2
Add transform_prior_samples and scaled prior plotting support
FBartos Feb 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
^doc$
^Meta$
^tests
^\.vscode$
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ if(interactive()){
library(devtools)
library(testthat)
library(vdiffr)
source("C:/R-Packages/BayesTools/tests/testthat/common-functions.R")
}
337 changes: 337 additions & 0 deletions .github/agents/Thinking-Beast-Mode.agent.md

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BayesTools is an R package for Bayesian analyses, JAGS model automation, and Bay

### Build & Test
- **Install**: `devtools::install()` (Timeout: 5m+)
- **Test**: `devtools::test()` (Timeout: 30m+)
- **Test**: `devtools::test()` (Timeout: 5m+)
- **Targeted Test**: `devtools::test(filter = 'priors')` (Recommended for dev)
- **Check**: `rcmdcheck::rcmdcheck(args = c('--no-manual', '--as-cran'), error_on = 'never')`
- **Docs**: `devtools::document()`
Expand All @@ -58,4 +58,11 @@ BayesTools is an R package for Bayesian analyses, JAGS model automation, and Bay
### Modifying JAGS Fitting
1. Edit `R/JAGS-fit.R` for general fitting logic or `R/JAGS-formula.R` for formula handling.
2. Verify with `devtools::test(filter = 'JAGS')`.
3. Ensure backward compatibility with `runjags` objects.
3. Ensure backward compatibility with `runjags` objects.

## Feature Addition Steps
1. Create unit tests verifying the desired behavior.
2. Implement the feature.
3. Verify the tests pass.
4. Update documentation as needed.
5. Update NEWS.md with a summary of changes.
77 changes: 77 additions & 0 deletions .github/instructions/r.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
description: 'R language and document formats (R, Rmd, Quarto): coding standards and Copilot guidance for idiomatic, safe, and consistent code generation.'
applyTo: '**/*.R, **/*.r, **/*.Rmd, **/*.rmd, **/*.qmd'
---

# R Programming Language Instructions

## Purpose

Help GitHub Copilot generate idiomatic, safe, and maintainable R code across projects.

## Core Conventions

- **Match the project’s style.** Follow the style in the project.
- **Prefer clear, vectorized code.** Keep functions small and avoid hidden side effects.
- **Qualify non-base functions in examples/snippets**, e.g., `dplyr::mutate()`, `stringr::str_detect()`.
- **Naming:** `lower_snake_case` for objects/files; use dots to dispatch different function types (and in S3 classes).
- **Side effects:** Never call `setwd()`; prefer project-relative paths (e.g., `here::here()`).
- **Validation:** Validate and constrain user inputs; use the predefined `check_bool()`, `check_char()`, `check_real()` ... functions.

### Pipe Operators

- **Never use pipe:** Always assign values using an arror `<-`

## Performance Considerations

- **Profiling:** Use `profvis::profvis()` to identify performance bottlenecks in your code. Profile before optimizing.
- **Caching:** Use `memoise::memoise()` to cache expensive function results. Particularly useful for repeated API calls or complex computations.
- **Vectorization:** Prefer vectorized operations over loops. Use `apply()` family for remaining iteration needs.

## Tooling & Quality

- **Pre-commit:** consider `precommit` hooks to lint/format automatically.
- **Docs:** roxygen2 for exported functions (`@param`, `@return`, `@examples`).
- **Tests:** prefer small, pure, composable functions that are easy to unit test.

## Data Wrangling & I/O

- **Data frames:** Use base `data.frame()`
- **Iteration:** Prefer type-stable, vectorized patterns such as `vapply()` (for atomic outputs). Use `for` loops when when they improve clarity or performance.
- **Strings & Dates:** Use clear base helpers (e.g., `nchar()`, `substr()`, `as.Date()` with explicit format).
- **I/O:** prefer explicit, typed readers (e.g., `readr::read_csv()`); make parsing assumptions explicit.

## Error Handling

- Use `stop(..., .call = FALSE)` / `warning()`.
- For recoverable operations:
- Use `tryCatch()` in base R for fine-grained control.

## Security Best Practices

- **Command execution:** Prefer `processx::run()` or `sys::exec_wait()` over `system()`; validate and sanitize all arguments.
- **File paths:** Normalize and sanitize user-provided paths (e.g., `fs::path_sanitize()`), and validate against allowlists.
- **Credentials:** Never hardcode secrets. Use env vars (`Sys.getenv()`), config outside VCS, or `keyring`.

## Copilot-Specific Guidance

- Suggest vectorized solutions over loops when idiomatic.
- Prefer small helper functions over long pipelines.
- When multiple approaches are equivalent, prefer readability and type stability and explain the trade-offs.

---

## Minimal Examples

```r
scores <- data.frame(id = 1:5, x = c(1, 3, 2, 5, 4))
safe_log <- function(x) tryCatch(log(x), error = function(e) NA_real_)
scores$z <- vapply(scores$x, safe_log, numeric(1))

# Example reusable helper with roxygen2 doc
#' Compute the z-score of a numeric vector
#' @param x A numeric vector
#' @return Numeric vector of z-scores
#' @examples z_score(c(1, 2, 3))
z_score <- function(x) (x - mean(x, na.rm = TRUE)) / stats::sd(x, na.rm = TRUE)
```
105 changes: 105 additions & 0 deletions .github/instructions/tests.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
description: 'R unit tests: testing standards and Copilot guidance for interaction with unit tests.'
applyTo: "**/tests/testthat/*.R"
---

# BayesTools Test Guidelines

## Overview

- Model fitting is centralized in `test-00-model-fits.R`; other tests load cached models
- **testthat Edition 3** - do not use `context()` calls
- Tests use `common-functions.R` for shared helpers

## Test Caching (TDD Workflow)

Model fitting is slow. The caching system lets you run the full suite once and reuse fits.

### Environment Variables

| Variable | Purpose | Default |
|----------|---------|---------|
| `BAYESTOOLS_TEST_FILES_DIR` | Cache directory location | `../temp/BayesTools_test_files` |
| `BAYESTOOLS_TEST_SKIP_REFIT` | Skip fitting if cache exists | TRUE |

### Recommended TDD Workflow

```r
# 1. Run full suite once to verify current code and populate cache (if missing)
devtools::test()

# 2. Iterate on your feature - uses cached fits unless you are modifing model fitting!
devtools::test(filter = "your-feature")

# 3. Final verification (disable cache if fit / marglik code or its dependencies changed)
clean_cached_fits()
devtools::test()
```

### When to Clear Cache

Clear with `clean_cached_fits()` when you modify:
- `JAGS_fit()` or `JAGS_bridgesampling()` logic (or any of its dependencies)
- Model definitions in `test-00-model-fits.R`

## Key Rules

### Model Fitting

- **Only `test-00-model-fits.R`** fits models and computes marginal likelihoods
- Other tests load with `readRDS(file.path(temp_fits_dir, "model_name.RDS"))`
- Check `model_registry.RDS` for available models before creating new ones

### File Naming

| Pattern | Purpose |
|---------|---------|
| `test-{feature}.R` | Main tests |
| `test-{feature}-input.R` | Input validation |
| `test-{feature}-coverage.R` | Edge cases |

### Skip Conditions

| Condition | When to Use |
|-----------|-------------|
| `skip_if_no_fits()` | Test loads pre-fitted models |
| `skip_if_not_installed("rjags")` | Test requires JAGS |
| `skip_if_not_installed("bridgesampling")` | Test computes marginal likelihoods |
| `skip_if_not_installed("vdiffr")` | Visual regression tests |

### Helper Functions (common-functions.R)

```r
source(testthat::test_path("common-functions.R"))

# Prior testing
test_prior(prior)
test_weightfunction(prior)
test_orthonormal(prior)

# Reference file testing
test_reference_table(table, filename)
test_reference_text(text, filename)

# Skip/cache helpers
skip_if_no_fits()
skip_refit_if_cached(name)
clean_cached_fits()
```

## AI Agent Protocol

1. **Scan `test-00-model-fits.R` first** - understand available models
2. **Reuse existing models** - don't create duplicates
3. **Never fit models** outside `test-00-model-fits.R`
4. **Never modify** `GENERATE_REFERENCE_FILES` flag (maintainer only)

## Troubleshooting

| Problem | Solution |
|---------|----------|
| "Pre-fitted models not available" | Run `devtools::test(filter = "00-model-fits")` |
| Stale cache causing failures | `clean_cached_fits()` then rerun |
| Tests pass locally, fail on CI | Clear cache, run full suite |

````
Loading
Loading