Skip to content

USCbiostats/barryr

Repository files navigation

barry: Your Go-To Motif Accountant (R Package) barry logo

ForeSITE Group CRAN status R-CMD-check CRANlogs downloads License: MIT codecov status

Synopsis

This R package provides C++ headers for the barry library, a C++ template library for counting sufficient statistics on binary arrays and building discrete exponential-family models. The barry library provides free portable C++ source code that is resolved entirely at compile-time without linking.

This package aims to make the barry library easily accessible to CRAN packages through the LinkingTo: field in the DESCRIPTION file. By placing these headers in this package, we offer a more efficient distribution system for CRAN as replication of this code in the sources of other packages is avoided. This follows the same approach as the BH package which provides Boost headers for R.

The barry library was created and is maintained by Dr. George G. Vega Yon as part of his doctoral dissertation "Essays on Bioinformatics and Social Network Analysis: Statistical and Computational Methods for Complex Systems."

Features

The barry C++ library includes the following key features:

  • Sparse arrays: Efficient handling of sparse binary arrays.
  • User-defined count statistics: Flexible framework for custom statistics.
  • Support set constraints: User-defined constraints on the support set.
  • Power set generation: Generation of binary array power sets.
  • Discrete Exponential Family Models (DEFMs): Module for building discrete exponential-family models.
  • Pooled DEFMs: Support for pooled data models.
  • Network counters: Statistics for network analysis including ERGMs (Exponential Random Graph Models).

Installation

You can install the development version of barry from GitHub with:

devtools::install_github("USCbiostats/barryr")

Or from R-universe (recommended for the latest development version):

install.packages(
  'barry',
  repos = c(
    'https://uscbiostats.r-universe.dev',
    'https://cloud.r-project.org'
  )
)

Usage

To use barry in your R package, add the following to your package's DESCRIPTION file:

LinkingTo: barry

Then in your C++ code, you can include barry headers:

#include <barry/barry.hpp>

// Your C++ code using barry here

The R package infrastructure tools will automatically set the include flags correctly on all architectures supported by R.

Example

Here is a simple example of using barry to count statistics in a network (from the barry C++ library documentation):

// [[Rcpp::depends(barry)]]

#include <Rcpp.h>
#include <barry/barry.hpp>

// [[Rcpp::export]]
Rcpp::NumericVector count_network_stats(
    size_t n,
    std::vector<size_t> source,
    std::vector<size_t> target
) {
  // Creating network 
  netcounters::Network net(n, n, source, target);
  net.set_data(new netcounters::NetworkData, true);
  
  // Creating counter object
  netcounters::NetStatsCounter<> counter(&net);
  
  // Adding statistics to count
  netcounters::counter_edges(counter.get_counters());
  netcounters::counter_mutual(counter.get_counters());
  netcounters::counter_ttriads(counter.get_counters());
  
  // Count and return
  std::vector<double> counts = counter.count_all();
  return Rcpp::wrap(counts);
}

/*** R
# Example usage
n <- 5
source <- c(0, 1, 2, 3, 0, 2)
target <- c(1, 2, 3, 4, 2, 0)
count_network_stats(n, source, target)
*/

Documentation

More information about the barry C++ library can be found:

See Also

Similar header-only R packages:

Code of Conduct

The barry project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

About

R bindings for the barry C++ library, your go-to motif accountant

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages