Learn R Programming

BigDataStatMeth

Overview

BigDataStatMeth provides scalable statistical computing for matrices stored in HDF5 files. The package is designed as a two-level tool: it provides a standard R interface for users working with HDF5-backed matrices, and a reusable C++ infrastructure for developers implementing new block-wise statistical methods.

The R interface is based on HDF5Matrix objects and S3 methods, so users can work with familiar R calls such as dim(), [, %*%, crossprod(), scale(), cor(), svd(), prcomp(), qr(), chol(), and solve(). The C++ infrastructure provides classes and routines for managing HDF5 files, groups, and datasets, together with block-wise numerical methods that can be reused from Rcpp-based code.

flowchart LR
    subgraph R["R interface"]
        A["HDF5Matrix objects"] --> B["S3 generics: scale, crossprod, svd, qr, prcomp ..."]
    end
    subgraph CPP["C++ infrastructure"]
        C["C++ classes: files, groups, datasets"] --> D["Block-wise numerical routines"]
    end
    B --> D
    D --> E["HDF5 storage on-disk matrices"]
    C --> E

Most users will interact with the R/S3 interface. Developers can build on the C++ headers to extend the package with new HDF5-backed methods while retaining efficient execution through compiled code.

Key Features

  • HDF5-backed matrices through a familiar HDF5Matrix/S3 interface
  • Block-wise algorithms — process matrices larger than available RAM through intelligent partitioning
  • Parallel processing — multi-threaded operations for enhanced performance
  • Comprehensive decompositions — SVD, PCA, QR, Cholesky, eigendecomposition, and pseudoinverse
  • Statistical transformations — centering, scaling, correlation, sweep, and aggregations by row/column
  • C++ developer infrastructure — reusable classes and routines for building new scalable methods without reimplementing HDF5 management or block iteration
  • HDF5 compression and file-space reuse — controlled disk usage across iterative workflows

Installation

From CRAN (Stable Release)

install.packages("BigDataStatMeth")

From GitHub (Development Version)

# Install devtools if needed
install.packages("devtools")

devtools::install_github("isglobal-brge/BigDataStatMeth")

System Requirements

R packages:

  • Matrix
  • RcppEigen
  • RSpectra

System dependencies:

  • HDF5 library (>= 1.8)
  • C++17 compatible compiler
  • For Windows: Rtools

Quick Start

library(BigDataStatMeth)

h5file <- tempfile(fileext = ".h5")

set.seed(1)
X <- matrix(rnorm(500 * 100), nrow = 500, ncol = 100)

# Write an in-memory matrix to HDF5
X_h5 <- hdf5_create_matrix(
  filename = h5file,
  dataset  = "data/X",
  data     = X,
  overwrite = TRUE
)

dim(X_h5)
colMeans(X_h5)

# Standard R operations on the HDF5-backed matrix
XtX_h5  <- crossprod(X_h5)
X_sc_h5 <- scale(X_h5)

# Decompositions
svd_res <- svd(X_h5, nu = 5, nv = 5, center = TRUE, scale = TRUE)
pca_res <- prcomp(X_h5, center = TRUE, scale. = TRUE, ncomponents = 5)

close(X_h5)
hdf5_close_all()

Core Functionality

Standard R interface (HDF5Matrix/S3)

CategoryRepresentative calls
Core object handlinghdf5_create_matrix(), hdf5_matrix(), dim(), nrow(), ncol(), is_open(), close()
HDF5 inspection and I/Olist_datasets(), hdf5_import(), hdf5_import_multiple(), as.matrix(), as.data.frame()
Subsetting and assignmentX[i, j], X[i, j] <- value
Dimension namesrownames(), colnames(), dimnames()
Element-wise arithmeticX + Y, X - Y, X * Y, X / Y
Matrix algebra%*%, crossprod(), tcrossprod(), cbind(), rbind()
AggregationscolSums(), rowSums(), colMeans(), rowMeans(), colVars(), rowVars(), colSds(), rowSds(), colMins(), rowMins(), colMaxs(), rowMaxs()
Scalar summariesmean(), var(), sd()
Normalization and transformationsscale(), sweep()
Correlationcor()
Decompositionssvd(), prcomp(), eigen(), pseudoinverse()
Factorizations and solversqr(), chol(), solve()
Diagonal operationsdiag(), diag<-(), diag_op(), diag_scale()
Split, reduce, and applysplit_dataset(), split(), reduce(), apply_function()
Resource management and optionshdf5matrix_options(), show_hdf5matrix_options(), hdf5_close_all()

Specialized helpers (bd*)

Some utilities do not map directly to an existing base R generic and retain the bd* prefix. Examples include bdCreate_hdf5_group(), bdmove_hdf5_dataset(), and bdWrite_hdf5_dimnames(). These functions are part of the package API and are documented in their corresponding help pages.

Global Options

Common settings for HDF5-backed computations can be configured with hdf5matrix_options(). These include parallel execution, number of threads, block size, and HDF5 compression level.

hdf5matrix_options(
  paral       = TRUE,
  threads     = 4L,
  block_size  = 512L,
  compression = 6L
)

These settings are especially useful for operations dispatched through standard R generics, where the usual R call does not always expose all low-level execution parameters. Operation-specific parameters can also be passed directly when a method supports them (see ?svd.HDF5Matrix, ?prcomp.HDF5Matrix, ?qr.HDF5Matrix).

C++ Infrastructure for New Methods

The C++ API is a central part of BigDataStatMeth. The package exposes C++ classes for HDF5 files, groups, and datasets, and implements block-wise routines for matrix algebra, decompositions, and statistical operations. These are the same building blocks used internally by the R/S3 interface.

This design allows developers to focus on the statistical or numerical method itself, rather than reimplementing HDF5 file handling, block iteration, or data movement.

#include <Rcpp.h>
#include "BigDataStatMeth.hpp"

using namespace BigDataStatMeth;

// [[Rcpp::export]]
void custom_analysis(std::string filename, std::string group, std::string dataset) {

    std::unique_ptr<BigDataStatMeth::hdf5Dataset> ds(nullptr);

    ds.reset( new BigDataStatMeth::hdf5Dataset(filename, group, dataset, false ) );
    ds->openDataset();

    // Block-wise processing using BigDataStatMeth routines
    // ...

    // ds is automatically closed and released when it goes out of scope
}

See Developing Methods for complete examples in both R and C++.

Documentation

Comprehensive documentation is available at https://isglobal-brge.github.io/BigDataStatMeth/

# List available vignettes
vignette(package = "BigDataStatMeth")

# View the main vignette
vignette("BigDataStatMeth")

Performance

BigDataStatMeth is designed for efficiency at scale:

  • Block-wise computation — process very large matrices with a controlled, fixed memory footprint
  • Parallel algorithms — multi-core support for matrix operations and decompositions
  • Optimized I/O — efficient HDF5 chunking and access patterns
  • File-space reuse — space released by removed or overwritten intermediate datasets is tracked and reused within the same file

Use Cases

BigDataStatMeth is suited for any analytical workflow that involves large matrix operations. Typical scenarios include:

  • Large-scale matrix computations — multiplication, crossproducts, and element-wise operations on matrices that exceed available RAM
  • Dimensionality reduction — PCA and SVD on wide or tall matrices stored on disk
  • Statistical inference — regression, Cholesky-based solvers, and correlation analysis at scale
  • Multi-dataset integration — combining and analyzing matrices across multiple data sources, with support for multi-omics workflows
  • Method development — building and prototyping new scalable statistical methods using the C++ infrastructure without reimplementing HDF5 management or block iteration

HDF5 Resource Management

HDF5-backed objects keep file handles open while they are in use. Objects can be closed individually with close(), and all open HDF5 handles managed by the package can be closed with hdf5_close_all().

close(X_h5)
hdf5_close_all()

After calling hdf5_close_all(), HDF5-backed objects that were open should be reopened before being used again. Calling gc() may also help trigger R finalizers for objects that are no longer referenced.

Citation

If you use BigDataStatMeth in your research, please cite:

Pelegri-Siso D, Gonzalez JR (2026). BigDataStatMeth: Statistical Methods
for Big Data Using Block-wise Algorithms and HDF5 Storage.
R package version 2.0.3, https://github.com/isglobal-brge/BigDataStatMeth

BibTeX entry:

@Manual{bigdatastatmeth,
  title  = {BigDataStatMeth: Statistical Methods for Big Data},
  author = {Dolors Pelegri-Siso and Juan R. Gonzalez},
  year   = {2026},
  note   = {R package version 2.0.3},
  url    = {https://github.com/isglobal-brge/BigDataStatMeth},
}

Contributing

Contributions are welcome. Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-feature)
  3. Commit your changes (git commit -m 'Add new feature')
  4. Push to the branch (git push origin feature/new-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow existing code style (Rcpp coding standards for C++, tidyverse style for R)
  • Add tests for new functionality
  • Update documentation — Roxygen2 for R functions, Doxygen for C++ headers
  • Run R CMD check before submitting

Getting Help

License

MIT License — see LICENSE file for details.

Authors

Dolors Pelegri-Siso Bioinformatics Research Group in Epidemiology (BRGE) ISGlobal — Barcelona Institute for Global Health

Juan R. Gonzalez Bioinformatics Research Group in Epidemiology (BRGE) ISGlobal — Barcelona Institute for Global Health

Acknowledgments

Development of BigDataStatMeth was supported by ISGlobal and the Bioinformatics Research Group in Epidemiology (BRGE).

Copy Link

Version

Install

install.packages('BigDataStatMeth')

Monthly Downloads

399

Version

2.0.3

License

MIT + file LICENSE

Maintainer

Dolors Pelegri-Siso

Last Published

July 6th, 2026

Functions in BigDataStatMeth (2.0.3)

bdmove_hdf5_dataset

Move HDF5 Dataset
can_allocate

Check if memory allocation is safe
bdgetDatasetsList_hdf5

List Datasets in HDF5 Group
chol.HDF5Matrix

Cholesky decomposition of a symmetric positive-definite HDF5Matrix
bdImportData_hdf5

Import data from URL or file to HDF5 format
bdblockSum

Block-Based Matrix Addition
colMins

Column and row minimums for HDF5Matrix
colMeans

Column and row means for HDF5Matrix
cbind.HDF5Matrix

Column-bind HDF5Matrix objects
crossprod

Cross product of HDF5Matrix objects
cor.HDF5Matrix

Correlation matrix for HDF5Matrix objects
bdtCrossprod

Efficient Matrix Transposed Cross-Product Computation
.get_option

Get global option value with fallback
cor

Correlation (generic)
bdpseudoinv_hdf5

Compute Matrix Pseudoinverse (HDF5-Stored)
diag<-

Set diagonal of an HDF5Matrix (generic)
get_available_ram

Get available (free) system RAM
hdf5_apply

Apply a mathematical operation to multiple HDF5 datasets
colesterol

Dataset colesterol
diag_scale

Scalar diagonal operation on an HDF5Matrix
dim.HDF5Matrix

Dimensions of an HDF5Matrix
colVars

Column and row variances for HDF5Matrix
get_total_ram

Get total system RAM
.hdf5matrix_options

HDF5Matrix Global Options
get_memory_thresholds

Get dynamic memory thresholds based on system RAM
get_cpu_cores

Get number of CPU cores
impute_snps

Impute missing SNP values in an HDF5Matrix
close.HDF5Matrix

Close HDF5Matrix
cancer

Cancer classification
get_recommended_threads

Get recommended number of threads for parallel operations
is_open

Check if HDF5Matrix is open
.onUnload

Package hook: cleanup on unload
diag

Extract or construct a diagonal for HDF5Matrix
colMaxs

Column and row maximums for HDF5Matrix
diag_op

Diagonal-vector operation on an HDF5Matrix
bdpseudoinv

Compute Matrix Pseudoinverse (In-Memory)
hdf5_import_multiple

Import multiple files into HDF5
miRNA

miRNA
hdf5_matrix

Open an HDF5 dataset as an HDF5Matrix object
hdf5_close_all

Close all HDF5Matrix objects
hdf5_close_file

Close all HDF5 handles for a specific file
colSds

Column and row standard deviations for HDF5Matrix
dimnames<-.HDF5Matrix

Set dimension names on an HDF5Matrix
dimnames.HDF5Matrix

Get dimension names of an HDF5Matrix
filter_low_coverage

Remove high-missingness features from an HDF5Matrix
filter_maf

Remove SNPs by Minor Allele Frequency from an HDF5Matrix
colSums

Column and row sums for HDF5Matrix
print.HDF5PCA

Print method for HDF5PCA objects
pseudoinverse

Moore-Penrose pseudoinverse
multiply_sparse

Sparse-aware matrix multiplication (generic)
hdf5_create_matrix

Create an HDF5 dataset and return an HDF5Matrix object
hdf5_import

Import data from file or URL into HDF5 format
multiply_sparse.HDF5Matrix

Sparse-aware matrix multiplication for HDF5Matrix
rcpp_hdf5dataset_rowMaxs

Row maximums of an HDF5 dataset (R6 wrapper)
rcpp_hdf5_close_all_registry

Close all open HDF5Dataset objects and HDF5 handles
rcpp_hdf5dataset_colMaxs

Column maximums of an HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_read_dimnames

Read dimension names (rownames / colnames) from an HDF5 dataset
rcpp_hdf5dataset_is_valid

Check if dataset is valid and open (R6 wrapper)
rcpp_hdf5_close_at_paths

Close all live HDF5Matrix handles pointing to specific dataset paths.
rcpp_hdf5dataset_close

Close and destroy an HDF5 dataset handle immediately.
object_size

Get memory size of HDF5Matrix without loading
memory_info

Print system memory information
eigen

Spectral decomposition
%*%

Matrix multiplication for HDF5Matrix
hdf5_reduce

Reduce all datasets in an HDF5 group by a binary operation
qr.HDF5Matrix

QR decomposition of an HDF5Matrix
rcpp_hdf5dataset_rowSds

Row standard deviations of an HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_rowSums

Row sums of an HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_info

Get dataset information (R6 wrapper)
qr

QR decomposition of an HDF5Matrix
rcpp_hdf5_create_matrix

Create an HDF5 dataset with configurable compression (R6 wrapper)
rcpp_hdf5dataset_colVars

Column variances of an HDF5 dataset (R6 wrapper)
hdf5matrix_options

Set or get HDF5Matrix computation options
rcpp_hdf5dataset_crossprod

Cross product for HDF5 datasets (R6 wrapper)
length.HDF5Matrix

Length of an HDF5Matrix
rbind.HDF5Matrix

Row-bind HDF5Matrix objects
list_datasets

List datasets in an HDF5 file or group
rcpp_hdf5dataset_open

Open HDF5 dataset and return external pointer (R6 wrapper)
rcpp_hdf5dataset_read_all

Get full dataset as matrix (convenience function)
rcpp_hdf5dataset_rowVars

Row variances of an HDF5 dataset (R6 wrapper)
prcomp.HDF5Matrix

Principal Component Analysis of an HDF5Matrix
print.HDF5Matrix

Print an HDF5Matrix object
rcpp_hdf5dataset_write_all

Write entire dataset (R6 wrapper)
rcpp_hdf5_close_all_file_handles

Close all open HDF5 file handles mid-session (safe)
rcpp_hdf5dataset_colMins

Column minimums of an HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_scalar_sd

Standard deviation of all elements of an HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_colMeans

Column means of an HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_write_block

Write data block to HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_scalar_max

Maximum of all elements of an HDF5 dataset (R6 wrapper)
show_hdf5matrix_options

Show current HDF5Matrix performance settings
rcpp_hdf5dataset_add

Element-wise addition of two HDF5 datasets (R6 wrapper)
rcpp_hdf5_close_file_handles

Close all HDF5 handles for a specific file (R6 wrapper)
rcpp_hdf5_close_file_handles_safe

Safely close all remaining HDF5 file handles (mid-session safe)
reduce

Reduce a group of HDF5 datasets by accumulation (generic)
rcpp_hdf5dataset_write_dimnames

Write dimension names through the R6 dataset handle
solve.HDF5Matrix

Matrix inverse of a symmetric positive-definite HDF5Matrix via Cholesky
rcpp_hdf5dataset_colSds

Column standard deviations of an HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_colSums

Column sums of an HDF5 dataset (R6 wrapper)
sweep

Sweep out array summaries (generic)
rcpp_hdf5dataset_dim

Get dimensions of HDF5 dataset (R6 wrapper)
split_dataset

Split an HDF5Matrix into multiple block datasets
rcpp_hdf5dataset_div_ew

Element-wise division of two HDF5 datasets (R6 wrapper)
split.HDF5Matrix

Split an HDF5Matrix into a list of blocks
svd

Singular Value Decomposition (generic)
system_info

Get system information summary
rcpp_hdf5dataset_scalar_var

Variance of all elements of an HDF5 dataset (R6 wrapper)
sweep.HDF5Matrix

Broadcast a vector over an HDF5Matrix (sweep)
str.HDF5Matrix

Structure of an HDF5Matrix object
sd

Standard deviation of all elements of an HDF5Matrix
scale

Scale / normalize an HDF5Matrix
rcpp_hdf5dataset_rowMins

Row minimums of an HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_subset

Read block from HDF5 dataset (subsetting)
rcpp_hdf5dataset_rowMeans

Row means of an HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_scalar_sum

Sum of all elements of an HDF5 dataset (R6 wrapper)
tcrossprod

Transposed cross product of HDF5Matrix objects
var

Variance of all elements of an HDF5Matrix
[.HDF5Matrix

Subset an HDF5Matrix
rcpp_hdf5dataset_mul_ew

Element-wise multiplication of two HDF5 datasets (R6 wrapper)
rcpp_hdf5dataset_tcrossprod

Transposed cross product for HDF5 datasets (R6 wrapper)
rcpp_hdf5dataset_subtract

Element-wise subtraction of two HDF5 datasets (R6 wrapper)
rcpp_hdf5dataset_scalar_min

Minimum of all elements of an HDF5 dataset (R6 wrapper)
[<-.HDF5Matrix

Subsetting assignment for HDF5Matrix objects
svd.HDF5Matrix

Singular Value Decomposition of an HDF5Matrix
rcpp_hdf5dataset_scalar_mean

Mean of all elements of an HDF5 dataset (R6 wrapper)
rcpp_hdf5dataset_multiply

General matrix product for HDF5 datasets (R6 wrapper)
apply_function

Apply a statistical or algebraic function to HDF5 datasets (generic)
as.data.frame.HDF5Matrix

Convert HDF5Matrix to data.frame
bdCreate_hdf5_matrix

Create HDF5 data file and write data to it
bdCreate_hdf5_group

Create Group in an HDF5 File
HDF5Matrix-S3

S3 methods for HDF5Matrix
BigDataStatMeth

BigDataStatMeth: Scalable statistical computing with R, C++, and HDF5
Ops.HDF5Matrix

Elementwise arithmetic operators for HDF5Matrix objects
as.matrix.HDF5Matrix

Convert HDF5Matrix to in-memory matrix
HDF5Matrix-scalar-aggregations

Summary statistics for HDF5Matrix
bdCorr_matrix

Compute correlation matrix for in-memory matrices (unified function)
bdImportTextFile_hdf5

Import Text File to HDF5
bdReduce_hdf5_dataset

Reduce Multiple HDF5 Datasets
bdWrite_hdf5_dimnames

Write dimnames to an HDF5 dataset
bdScalarwproduct

Matrix–scalar weighted product
bdblockMult

Block-Based Matrix Multiplication
bdblockSubstract

Block-Based Matrix Subtraction
bdCrossprod

Efficient Matrix Cross-Product Computation
bd_wproduct

Weighted matrix–vector products and cross-products
bdapply_Function_hdf5

Apply function to different datasets inside a group