Thank you for your interest in contributing to PVgravID! This document provides guidelines and instructions for contributing to the project.
Getting Started
Required R Packages
The package depends on several R packages. The main dependency is DiAna, which is not on CRAN but available on GitHub.
Development Setup
2. Install Development Dependencies
# Install devtools if you don't have it
install.packages("devtools")
# Install package dependencies (including DiAna from GitHub)
devtools::install_deps(dependencies = TRUE)
# Install development tools
install.packages(c("testthat", "lintr", "styler"))Coding Standards
We follow the tidyverse style guide for R code. Please ensure your code adheres to these standards before submitting.
Style Guide
- Use 2 spaces for indentation (never tabs)
- Maximum line length: 120 characters
- Use
snake_casefor function and variable names - Use
<-for assignment, not= - Put spaces around operators (
x + y, notx+y) - Use double quotes for strings (
"text", not'text')
Automatic Formatting
Before submitting code, run styler to automatically format your code:
# Format a single file
styler::style_file("R/your_file.R")
# Format all R files
styler::style_dir("R")
# Format test files
styler::style_dir("tests/testthat")Linting
Check your code for style issues:
# Lint the entire package
lintr::lint_package()
# Lint a specific file
lintr::lint("R/your_file.R")Pull Request Process
Before Submitting
Run the local checks to ensure your changes pass all tests:
devtools::load_all()
devtools::check()
devtools::test()
styler::style_dir("R")
styler::style_dir("tests/testthat")
lintr::lint_package()This script runs:
- R CMD check (package validation)
- Linting (code style)
- Tests (testthat)
All checks must pass before submitting a PR.
Submitting a Pull Request
-
Create a branch for your changes:
Make your changes following the coding standards
Add tests for your changes
-
Update documentation:
# Update function documentation with roxygen2 devtools::document() -
Run local checks:
Check that all tests pass and code is lint-free.
-
Commit your changes:
-
Push to your fork:
-
Open a Pull Request on GitHub with:
- Clear description of changes
- Reference to any related issues
- Confirmation that all checks pass
Documentation
Function Documentation
Use roxygen2 comments for all exported functions:
#' Short description of function
#'
#' Longer description with more details about what the function does.
#'
#' @param database Database name (e.g., "24Q4", "VigiBase", "sample")
#' @param pids_vct Vector of primary IDs
#'
#' @return Description of return value
#'
#' @examples
#' \dontrun{
#' result <- my_function(database = "sample", pids_vct = c(1, 2, 3))
#' }
#'
#' @export
my_function <- function(database, pids_vct) {
# function code
}Project Structure
PVgravID/
├── R/ # R source code
│ ├── check_pregnancy_criteria.R
│ ├── flowchart_generator.R
│ ├── globals.R
│ ├── modular_data.R
│ ├── render_Upset.R
│ ├── render_Venn.R
│ └── ...
├── tests/
│ └── testthat/ # Test files
├── man/ # Generated documentation
├── .github/workflows/ # CI/CD workflows
├── DESCRIPTION # Package metadata
├── NAMESPACE # Auto-generated
└── README.md
