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

View source: R/crochet.R

ReplaceR Documentation

Create an Implementation of [<- For Custom Matrix-Like Types

Description

replace 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 replace_vector or i and j parameters of replace_matrix to facilitate implementing the replacement mechanism for custom matrix-like types. Single values are recycled to match the replacement length.

Usage

Replace(replace_vector, replace_matrix)

Arguments

replace_vector

A function in the form of ⁠function(x, i, value)⁠ that replaces a vector subset of x based on a single vector of indices i with the values in value and returns x, invisibly.

replace_matrix

A function in the form of ⁠function(x, i, j, value)⁠ that replaces a matrix subset of x based on two vectors of indices i and j with the values in value and returns x, invisibly.

Details

This idea initially comes from package crochet.

Value

A function in the form of ⁠function(x, i, j, ..., value)⁠ that is meant to be used as a method for ⁠[<-⁠ for a custom type.


bigstatsr documentation built on Sept. 11, 2024, 7:08 p.m.