Extract: Create an Implementation of [ For Custom Matrix-Like Types

View source: R/crochet.R

ExtractR Documentation

Create an Implementation of [ For Custom Matrix-Like Types

Description

extract is a function that converts different index types such as negative integer vectors or logical vectors passed to the [ function as i (e.g. X[i]) or i and j (e.g. X[i, j]) into positive integer vectors. The converted indices are provided as the i parameter of extract_vector or i and j parameters of extract_matrix to facilitate implementing the extraction mechanism for custom matrix-like types.

Usage

Extract(extract_vector, extract_matrix)

Arguments

extract_vector

A function in the form of function(x, i) that takes a subset of x based on a single vector of indices i and returns a vector.

extract_matrix

A function in the form of function(x, i, j) that takes a subset of x based on two vectors of indices i and j and returns a matrix.

Details

This idea initially comes from package crochet.

Value

A function in the form of function(x, i, j, ..., drop = TRUE) that is meant to be used as a method for [ for a custom type.


bigstatsr documentation built on Oct. 14, 2022, 9:05 a.m.