Package 'fastMatMR'

Title: High-Performance Matrix Market File Operations
Description: An interface to the 'fast_matrix_market' 'C++' library, this package offers efficient read and write operations for Matrix Market files in R. It supports both sparse and dense matrix formats. Peer-reviewed at ROpenSci (<https://github.com/ropensci/software-review/issues/606>).
Authors: Rohit Goswami [aut, cre] , Ildiko Czeller [rev] , Adam Lugowski [ctb]
Maintainer: Rohit Goswami <[email protected]>
License: MIT + file LICENSE
Version: 1.2.5
Built: 2024-11-27 03:24:11 UTC
Source: https://github.com/ropensci/fastMatMR

Help Index


Convert Matrix Market File to Matrix

Description

This function reads a Matrix Market file and converts it to a matrix in R.

Usage

fmm_to_mat(filename)

Arguments

filename

The name of the input Matrix Market file to be read.

Value

A matrix containing the data read from the Matrix Market file.

Examples

# Create
sample_mat <- matrix(c(1, 2, 3, 4), nrow = 2)
temp_file_mat <- tempfile(fileext = ".mtx")
write_fmm(sample_mat, temp_file_mat)
# Read
mat <- fmm_to_mat(temp_file_mat)

Convert Matrix Market File to Sparse Matrix

Description

This function reads a Matrix Market file and converts it to a sparse matrix in R using the Matrix package.

Usage

fmm_to_sparse_Matrix(filename)

Arguments

filename

The name of the input Matrix Market file to be read.

Value

A dgCMatrix object containing the data read from the Matrix Market file.

Examples

# Create
sample_sparse_mat <- Matrix::Matrix(c(1, 0, 0, 2), nrow = 2, sparse = TRUE)
temp_file <- tempfile(fileext = ".mtx")
write_fmm(sample_sparse_mat, temp_file)
# Read
sparse_mat <- fmm_to_sparse_Matrix(temp_file)

Convert Matrix Market File to Numeric Vector

Description

This function reads a Matrix Market file and converts it to a numeric vector in R.

Usage

fmm_to_vec(filename)

Arguments

filename

The name of the input Matrix Market file to be read.

Value

A numeric vector containing the data read from the Matrix Market file.

Examples

# Create
sample_vec <- c(1, 2, 3)
temp_file_vec <- tempfile(fileext = ".mtx")
write_fmm(sample_vec, temp_file_vec)
# Read
vec <- fmm_to_vec(temp_file_vec)

Convert a Numeric Matrix to Matrix Market Format

Description

This function takes a numeric matrix and converts it into a Matrix Market file.

Arguments

input

A numeric matrix to be converted.

filename

The name of the output file where the Matrix Market formatted data will be saved.

Value

A boolean indicating success or failure. Writes a MTX file to disk.

Examples

intmat <- matrix(c(1L, 2L, 3L, 4L), nrow = 2)
intmat_to_fmm(intmat, tempfile(fileext = ".mtx"))

Convert a numeric integer vector to Matrix Market Format

Description

This function takes a numeric intvector and converts it into a Matrix Market output file.

Arguments

input

A numeric integer vector to be converted.

filename

The name of the output file where the Matrix Market formatted data will be saved.

Value

A boolean indicating success or failure. Writes a MTX file to disk.

Examples

intvec <- c(1L, 2L, 3L)
intvec_to_fmm(intvec, tempfile(fileext = ".mtx"))

Convert a Numeric Matrix to Matrix Market Format

Description

This function takes a numeric matrix and converts it into a Matrix Market file.

Arguments

input

A numeric matrix to be converted.

filename

The name of the output file where the Matrix Market formatted data will be saved.

Value

A boolean indicating success or failure. Writes a MTX file to disk.

Examples

mat <- matrix(c(1, 2, 3, 4), nrow = 2)
mat_to_fmm(mat, tempfile(fileext = ".mtx"))

Convert a Sparse Numeric Matrix to Matrix Market Format

Description

This function takes a sparse numeric matrix and converts it into a Matrix Market file.

Arguments

input

A sparse numeric matrix to be converted.

filename

The name of the output file where the Matrix Market formatted data will be saved.

Value

A boolean indicating success or failure. Writes a MTX file to disk.

Examples

sparse_mat <- Matrix::Matrix(c(1, 0, 0, 2), nrow = 2, sparse = TRUE)
sparse_Matrix_to_fmm(sparse_mat, tempfile(fileext = ".mtx"))

Convert a Numeric Vector to Matrix Market Format

Description

This function takes a numeric vector and converts it into a Matrix Market output file.

Arguments

input

A numeric vector to be converted.

filename

The name of the output file where the Matrix Market formatted data will be saved.

Value

A boolean indicating success or failure. Writes a MTX file to disk.

Examples

vec <- c(1, 2, 3)
vec_to_fmm(vec, tempfile(fileext = ".mtx"))

Convert Various Numeric Types to Matrix Market Format

Description

This function takes different types of numeric inputs—vectors, matrices, and sparse matrices— and converts them into Matrix Market files. The output file is written to disk.

Usage

write_fmm(input, filename = "out.mtx")

Arguments

input

A numeric object to be converted. This can be a numeric vector, a matrix, or a sparse matrix.

filename

The name of the output file where the Matrix Market formatted data will be saved. It is recommended to use a filename ending with ".mtx" for clarity.

Value

A boolean indicating success or failure. Writes a MTX file to disk.

Examples

vec <- c(1, 2, 3)
mat <- matrix(c(1, 2, 3, 4), nrow = 2)
sparse_mat_diag <- Matrix::Matrix(c(1, 0, 0, 2), nrow = 2, sparse = TRUE)
## Diagonal ^-
sparse_mat <- Matrix::Matrix(c(1, 1, 0, 2), nrow = 2, sparse = TRUE)
## And not diagonal -^
write_fmm(vec, tempfile(fileext = ".mtx"))
write_fmm(mat, tempfile(fileext = ".mtx"))
write_fmm(sparse_mat_diag, tempfile(fileext = ".mtx"))
write_fmm(sparse_mat, tempfile(fileext = ".mtx"))