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.”
The barry C++ library includes the following key features:
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'
)
)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:
The R package infrastructure tools will automatically set the include flags correctly on all architectures supported by R.
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)
*/Similar header-only R packages:
The barry project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.