diff --git a/.Rbuildignore b/.Rbuildignore index 0f64d8f..40982c5 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -16,3 +16,4 @@ ^\.pixi ^cran-comments\.md$ ^LICENSE\.md$ +^README\.md$ diff --git a/.github/environment/pixi.toml b/.github/environment/pixi.toml index 90f5821..53cd3f8 100644 --- a/.github/environment/pixi.toml +++ b/.github/environment/pixi.toml @@ -11,7 +11,7 @@ devtools_document = "R -e 'devtools::document()'" devtools_test = "R -e 'devtools::test()'" codecov = "R -e 'covr::codecov(quiet = FALSE)'" build = "R -e 'devtools::build()'" -rcmdcheck = "R -e 'pkg <- list.files(\"..\", pattern = \".tar.gz\", full.names = TRUE); rcmdcheck::rcmdcheck(path = pkg[1], args = c(\"--as-cran\"))'" +rcmdcheck = "R -e 'pkg <- list.files(\"..\", pattern = \".tar.gz\", full.names = TRUE); rcmdcheck::rcmdcheck(path = pkg[1], args = c(\"--as-cran\", \"--no-manual\"))'" use_major_version = "R -e 'usethis::Use_version(which = \"major\", push = FALSE)'" use_minor_version = "R -e 'usethis::use_version(which = \"minor\", push = FALSE)'" use_patch_version = "R -e 'usethis::use_version(which = \"patch\", push = FALSE)'" diff --git a/DESCRIPTION b/DESCRIPTION index b0f74b5..9965c63 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: colocboost Type: Package -Date: 2024-09-01 +Date: 2025-04-13 Title: Multi-Context Colocalization Analysis Tool for Molecular QTL and GWAS Studies Version: 0.1.0 Authors@R: c( diff --git a/R/colocboost.R b/R/colocboost.R index c53bf83..17942ee 100644 --- a/R/colocboost.R +++ b/R/colocboost.R @@ -13,7 +13,6 @@ #' (default is 0.8) but within the same locus. This step addresses potential instabilities in linkage disequilibrium (LD) estimation #' that may arise from small sample sizes or discrepancies in minor allele frequencies (MAF) across different confidence sets. #' -#' @section Input Data: #' @param X A list of genotype matrices for different outcomes, or a single matrix if all outcomes share the same genotypes. #' Each matrix should have column names, if sample sizes and variables possibly differing across matrices. #' @param Y A list of vectors of outcomes or an N by L matrix if it is considered for the same X and multiple outcomes. @@ -40,7 +39,6 @@ #' @param effect_se Matrix of standard errors associated with the beta values #' @param effect_n A scalar or a vector of sample sizes for estimating regression coefficients. Highly recommended! #' -#' @section Model Parameters #' @param M The maximum number of gradient boosting rounds. If the number of outcomes are large, it will be automatically increased to a larger number. #' @param stop_thresh The stop criterion for overall profile loglikelihood function. #' @param tau The smooth parameter for proximity adaptive smoothing weights for the best update jk-star. @@ -64,7 +62,6 @@ #' @param p.adjust.methods The adjusted pvalue method in stats:p.adj when \code{func_multi_test = "fdr"} #' @param residual_correlation The residual correlation based on the sample overlap, it is diagonal if it is NULL. #' -#' @section Post Inference Parameters #' @param coverage A number between 0 and 1 specifying the \dQuote{coverage} of the estimated colocalization confidence sets (CoS) (default is 0.95). #' @param min_cluster_corr The small correlation for the weights distributions across different iterations to be decided having only one cluster. #' @param dedup If \code{dedup = TRUE}, the duplicate confidence sets will be removed in the post-processing. diff --git a/man/colocboost.Rd b/man/colocboost.Rd index d10c19f..c712a63 100644 --- a/man/colocboost.Rd +++ b/man/colocboost.Rd @@ -208,18 +208,6 @@ There is an additional step to help merge the confidence sets with small \code{b (default is 0.8) but within the same locus. This step addresses potential instabilities in linkage disequilibrium (LD) estimation that may arise from small sample sizes or discrepancies in minor allele frequencies (MAF) across different confidence sets. } -\section{Input Data}{ - -} - -\section{Model Parameters}{ -NA -} - -\section{Post Inference Parameters}{ -NA -} - \examples{ colocboost(X=X, Y=Y) diff --git a/tests/README.md b/tests/README.md index 1ec2832..54c6810 100644 --- a/tests/README.md +++ b/tests/README.md @@ -2,39 +2,29 @@ ## Overview -This repository contains a comprehensive testing framework for the [colocboost](https://github.com/StatFunGen/colocboost) R package. The framework is designed to ensure the reliability and correctness of the package's functionality through automated testing. +This repository contains a comprehensive testing framework for the [colocboost](https://github.com/StatFunGen/colocboost) R package. The framework is designed to ensure the reliability and correctness of package functionality through automated testing. ## Quick Start -1. Navigate to test folder: - ```bash - cd tests - ``` +1. Our unit testing setup is managed by `pixi`. Please follow the instructions at [https://pixi.sh/latest/#installation](https://pixi.sh/latest/#installation) if you have not already installed `pixi`. -2. **First time use**: run the setup script to install required packages and configure the testing environment: - ```r - # install.packages(c("devtools", "testthat", "covr", "roxygen2")) - source("setup_testthat.R") - ``` +2. In the root of this repository, run the helper script to create a pixi.toml file. This file is deliberately ignored in `.gitignore` because it is ephemeral and will be regenerated whenever CI is run. + + ```bash + .github/workflows/create_toml_from_yaml.sh $(pwd) + ``` -3. Run all tests: - ```r - devtools::load_all() - devtools::test() - ``` - or, +3. Run all tests with a `pixi` task: ```bash - Rscript run_tests.R + pixi run devtools_test ``` - To test one file: - ```r - devtools::test_active_file("testthat/test_colocboost.R") + or test one file using `pixi run`: + ```bash + pixi run R -e 'devtools::test_active_file("tests/testthat/test_colocboost.R")' ``` ## Files and Structure -- `setup_testthat.R`: Script to set up the testthat infrastructure -- `run_tests.R`: Script to run all tests and generate test coverage reports - `testthat/`: Directory containing test files - `test_package.R`: Tests for basic package functionality - `test_colocboost.R`: Tests for the main colocalization functions @@ -42,22 +32,6 @@ This repository contains a comprehensive testing framework for the [colocboost]( - `test_model.R`: Tests for model fitting and prediction functions - `.github/workflows/`: GitHub Actions workflow configurations -## How To Use - -### Running Tests Locally - -To run the tests locally, you can use: - -```r -devtools::test() -``` - -Or run individual test files: - -```r -devtools::test_file("testthat/test_colocboost.R") -``` - ### Adding New Tests When adding new functionality to the colocboost package, corresponding tests should be added to maintain test coverage. Follow these steps: @@ -84,23 +58,21 @@ test_that("new_function produces expected output", { ### Test Coverage -The `covr` package is used to measure test coverage, which indicates what percentage of your code is being tested. Aim for at least 80% coverage for a reliable package. +The `covr` package is used to measure test coverage, which indicates what percentage of the code is being tested. To generate a test coverage report: -```r -library(covr) -coverage <- package_coverage() -report(coverage) +```bash +pixi run codecov ``` ## GitHub Actions Workflow -This testing framework includes GitHub Actions workflows that automatically run the tests on every push and pull request. The workflows test the package on multiple operating systems (Windows, macOS, and Linux) to ensure cross-platform compatibility. +This testing framework includes GitHub Actions workflows that automatically run the tests on every pull request. The workflows test the package on Linux and macOS to ensure cross-platform compatibility. -The workflow is defined in `.github/workflows/R-CMD-check.yaml` and automatically runs: -- R CMD check -- Test coverage reporting +The workflow is defined in `.github/workflows/ci.yaml` and automatically runs: +- `R CMD check` +- Test coverage reporting with [codecov.io](codecov.io) -Test results and coverage statistics are available on the GitHub Actions page after each push or pull request. +Test results and coverage statistics are available on the GitHub Actions page after each pull request. For more information, check the [testthat documentation](https://testthat.r-lib.org/). diff --git a/tests/run_tests.R b/tests/run_tests.R deleted file mode 100644 index 4ac19a2..0000000 --- a/tests/run_tests.R +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env Rscript - -# Script to install the package and run tests - -# Check for required packages -required_packages <- c("devtools", "testthat", "covr") -for (pkg in required_packages) { - if (!requireNamespace(pkg, quietly = TRUE)) { - stop(sprintf("Cannot find required package: %s\n", pkg)) - } -} - -# Path to working directory -args <- commandArgs(trailingOnly = TRUE) -if (length(args) > 0) { - work_dir <- args[1] -} else { - work_dir <- getwd() -} - -setwd(work_dir) -cat(sprintf("Working directory: %s\n", work_dir)) - -# Install the package -# cat("Installing colocboost package...\n") -# devtools::install(".", dependencies = FALSE, quiet = TRUE) - -# Run tests -cat("Running tests...\n") -devtools::load_all('../') -testthat::test_dir("testthat/") - -# Calculate test coverage -cat("Calculating test coverage...\n") -coverage <- covr::package_coverage() -print(coverage) -covr::report(coverage) - -cat("Tests completed.\n") \ No newline at end of file diff --git a/tests/setup_testthat.R b/tests/setup_testthat.R deleted file mode 100644 index caab98f..0000000 --- a/tests/setup_testthat.R +++ /dev/null @@ -1,130 +0,0 @@ -setwd("../") - -# Install necessary packages -if (!requireNamespace("devtools", quietly = TRUE)) { - stop("devtools not found") -} -if (!requireNamespace("testthat", quietly = TRUE)) { - stop("testthat not found") -} -if (!requireNamespace("covr", quietly = TRUE)) { - stop("covr not found") -} -if (!requireNamespace("roxygen2", quietly = TRUE)) { - stop("roxygen2 not found") -} - -# Set up testthat infrastructure -if (!dir.exists("tests/testthat")) { - devtools::use_testthat() -} - -# Create GitHub Actions workflow for continuous integration -if (!dir.exists(".github/workflows")) { - dir.create(".github/workflows", recursive = TRUE, showWarnings = FALSE) -} - -# Write GitHub Actions workflow file -workflow_file <- ".github/workflows/R-CMD-check.yaml" -writeLines( -' -on: - push: - branches: [main, master] - pull_request: - branches: [main, master] - -name: R-CMD-check - -jobs: - R-CMD-check: - runs-on: ${{ matrix.config.os }} - - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - - strategy: - fail-fast: false - matrix: - config: - - {os: windows-latest, r: "release"} - - {os: macOS-latest, r: "release"} - - {os: ubuntu-latest, r: "release"} - - env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v2 - with: - r-version: ${{ matrix.config.r }} - - - uses: r-lib/actions/setup-pandoc@v2 - - - name: Install dependencies - run: | - install.packages(c("remotes", "rcmdcheck", "covr", "testthat")) - remotes::install_deps(dependencies = TRUE) - shell: Rscript {0} - - - name: Check - run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} - - - name: Test coverage - run: covr::codecov() - shell: Rscript {0} -', workflow_file) - -# Create a test coverage workflow -coverage_file <- ".github/workflows/test-coverage.yaml" -writeLines( -' -on: - push: - branches: [main, master] - pull_request: - branches: [main, master] - -name: test-coverage - -jobs: - test-coverage: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v2 - - - name: Install dependencies - run: | - install.packages(c("remotes", "covr")) - remotes::install_deps(dependencies = TRUE) - shell: Rscript {0} - - - name: Test coverage - run: covr::codecov() - shell: Rscript {0} -', coverage_file) - -# Add code coverage badge to README.md -readme_file <- "README.md" -if (file.exists(readme_file)) { - readme_content <- readLines(readme_file) - if (!any(grepl("codecov", readme_content))) { - badge <- "[![Codecov test coverage](https://codecov.io/gh/StatFunGen/colocboost/branch/master/graph/badge.svg)](https://codecov.io/gh/StatFunGen/colocboost?branch=master)" - # Add badge after the first line if it's a title - if (length(readme_content) > 0) { - readme_content <- c(readme_content[1], badge, readme_content[-1]) - } else { - readme_content <- c("# colocboost", badge) - } - writeLines(readme_content, readme_file) - } -} - -# Set up basic testthat structure -message("testthat setup complete. Next, create test files for each R file in the package.") \ No newline at end of file