Contributing to gwArsenicR
Thank you for your interest in contributing to gwArsenicR! This document provides guidelines for contributing to the project.
Code of Conduct
We are committed to providing a welcoming and inclusive environment for all contributors. Please be respectful and professional in all interactions.
Getting Started
Prerequisites
- R (β₯ 4.4.0)
- VS Code (recommended)
- Git
- Pandoc for building vignettes
Required R Packages
# Development tools
install.packages(c("devtools", "roxygen2", "testthat", "covr"))
# Package dependencies (see DESCRIPTION file)
install.packages(c("data.table", "dplyr", "lme4", "mice", "broom.mixed"))
Development Setup
Fork the repository on GitHub
-
Clone your fork locally:
-
Set up the development environment:
-
Create a new branch for your contribution:
How to Contribute
We welcome several types of contributions:
π Bug Reports
- Search existing issues first
- Use the bug report template
- Include reproducible examples
- Specify R version and package version
π‘ Feature Requests
- Check if the feature already exists
- Clearly describe the use case
- Explain why it would be valuable
- Consider backward compatibility
Reporting Issues
When reporting issues, please include:
For Bug Reports
Describe the bug: Clear description of what happened
Reproduction steps: Minimal code to reproduce the issue
Expected behavior: What you expected to happen
-
System information:
sessionInfo() packageVersion("gwArsenicR")
Data: If possible, provide sample data that reproduces the issue
Submitting Pull Requests
Before Submitting
-
Ensure your code passes all checks:
-
Update documentation if needed:
devtools::document()
Add tests for new functionality
Update NEWS.md with your changes
Pull Request Process
-
Commit your changes with clear, descriptive messages:
-
Push to your fork:
-
Create a pull request on GitHub with:
- Clear title describing the change
- Detailed description of what was changed and why
- Reference to any related issues
- Confirmation that tests pass
Respond to review feedback promptly and professionally
Development Guidelines
Code Style
Follow the tidyverse style guide:
# Good
calculate_arsenic_exposure <- function(data, method = "weighted") {
if (is.null(data)) {
stop("Data cannot be NULL")
}
result <- data %>%
filter(!is.na(arsenic_level)) %>%
summarize(mean_exposure = mean(arsenic_level))
return(result)
}
# Function names: snake_case
# Variable names: snake_case
# Constants: UPPER_SNAKE_CASE
# Use explicit returns
# Add input validation
Package Structure
gwArsenicR/
βββ R/
β βββ gwArsenic.R # Main exported function
β βββ data-loading.R # Data loading functions
β βββ imputation.R # Imputation functions
β βββ regression.R # Analysis functions
β βββ utils.R # Utility functions
βββ tests/testthat/ # Test files
βββ man/ # Generated documentation
βββ vignettes/ # Package vignettes
βββ inst/ # Additional package files
Function Guidelines
- Single responsibility: Each function should do one thing well
- Clear naming: Function names should describe what they do
- Input validation: Check arguments and provide helpful error messages
- Documentation: Use roxygen2 for all exported functions
- Error handling: Use informative error messages
Testing
Writing Tests
- Use
testthat
framework - Test both success and failure cases
- Use descriptive test names
- Test edge cases and error conditions
test_that("load_usgs_data handles missing columns gracefully", {
# Create test data missing required column
test_data <- data.frame(wrong_col = 1:10)
expect_error(
load_usgs_data(test_data, required_cols = "correct_col"),
"missing columns"
)
})
test_that("arsenic imputation produces valid probabilities", {
results <- impute_arsenic_exposure(test_data, ndraws = 2)
expect_true(all(results$probabilities >= 0))
expect_true(all(results$probabilities <= 1))
expect_equal(length(results$datasets), 2)
})
Documentation
Function Documentation
Use roxygen2 for all exported functions:
#' Perform Arsenic Exposure Analysis
#'
#' This function performs a comprehensive analysis of arsenic exposure
#' using multiple imputation and mixed-effects modeling.
#'
#' @param data A data frame containing the input data
#' @param ndraws An integer specifying the number of imputed datasets (default: 10)
#' @param output_dir A character string specifying the output directory
#' @return A list containing analysis results and summary statistics
#' @examples
#' \dontrun{
#' results <- perform_sensitivity_analysis(
#' data = my_data,
#' ndraws = 5,
#' output_dir = "results/"
#' )
#' }
#' @export
Release Process
Versioning
We use Semantic Versioning: - MAJOR.MINOR.PATCH (e.g., 1.2.3) - MAJOR: Incompatible API changes - MINOR: New functionality (backward compatible) - PATCH: Bug fixes (backward compatible)
Release Checklist
- Update version in
DESCRIPTION
- Update
NEWS.md
with changes - Run comprehensive tests:
devtools::check()
- Update documentation:
devtools::document()
- Build and test package
- Create GitHub release with release notes
Getting Help
Questions and Discussions
- GitHub Discussions: For questions about usage or development
- GitHub Issues: For bug reports and feature requests
- Email: Contact maintainers for sensitive issues
Resources
- R Packages book by Hadley Wickham
- Advanced R for advanced R programming
- testthat documentation for testing
- roxygen2 documentation for documentation
Recognition
Contributors will be acknowledged in: - DESCRIPTION
file (for significant contributions) - README.md
contributors section - Release notes for their contributions
Thank you for contributing to gwArsenicR! Your efforts help advance arsenic exposure research and public health.
Questions? Feel free to open an issue or contact the maintainers: - Dr.Β Sayantan Majumdar - Dr.Β Matthew O. Gribble