Package 'distops'

Title: Usual Operations for Distance Matrices in R
Description: It provides the subset operator for dist objects and a function to compute medoid(s) that are fully parallelized leveraging the 'RcppParallel' package. It also provides functions for package developers to easily implement their own parallelized dist() function using a custom 'C++'-based distance function.
Authors: Aymeric Stamm [aut, cre]
Maintainer: Aymeric Stamm <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-10-25 05:32:51 UTC
Source: https://github.com/lmjl-alea/distops

Help Index


distops: Usual Operations for Distance Matrices in R

Description

It provides the subset operator for dist objects and a function to compute medoid(s) that are fully parallelized leveraging the 'RcppParallel' package. It also provides functions for package developers to easily implement their own parallelized dist() function using a custom 'C++'-based distance function.

Author(s)

Maintainer: Aymeric Stamm [email protected] (ORCID)

See Also

Useful links:


Distance Matrix Subset Operator

Description

Subset operator for the distance matrix stored as an object of class stats::dist.

Usage

## S3 method for class 'dist'
x[i, j, drop = TRUE, ...]

Arguments

x

An object of class stats::dist.

i

An integer vector of row indices. Values must be either all positive in which case they indicate the rows to select, or all negative in which case they indicate the rows to omit.

j

An integer vector of column indices. Values must be either all positive in which case they indicate the columns to select, or all negative in which case they indicate the columns to omit.

drop

A logical value indicating whether the result should be coerced to a vector or matrix if possible.

...

Additional arguments passed to ⁠[.dist⁠.

Value

A numeric matrix storing the pairwise distances between the requested observations.

Examples

D <- stats::dist(iris[, 1:4])
D[2:3, 7:12]

Finds the medoids from a distance matrix

Description

This function finds the medoids from a distance matrix. The medoid is the object that minimizes the sum of distances to all other objects. This function takes advantage of the RcppParallel package to compute the medoids in parallel.

Usage

find_medoids(D, memberships = NULL)

Arguments

D

An object of class stats::dist.

memberships

A factor specifying the cluster memberships of the objects.

Value

A named integer vector specifying the indices of the medoids.

Examples

D <- stats::dist(iris[, 1:4])
find_medoids(D)
memberships <- as.factor(rep(1:3, each = 50L))
find_medoids(D, memberships)

Adds a distance function to the package

Description

This function adds a distance function to the package. It first creates the ⁠R/{distance_name}Distance.R⁠ file with the R wrapper function for the distance function. It then creates the ⁠src/{distance_name}Distance.cpp⁠ file with the C++ implementation of the distance function. It finally opens the latter file in the default editor. The user will be able to implement the desired distance function in a way compatible with the RcppParallel workflow.

Usage

use_distance(distance_name)

Arguments

distance_name

A character string specifying the name of the distance that the user aims at implementing.

Value

Nothing.

Examples

use_distance("euclidean")

Setups package to use the distops package

Description

This function setups the package to use the distops package. It first creates the DESCRIPTION file adding the Rcpp and RcppParallel packages to both the ⁠Imports:⁠ and ⁠LinkingTo:⁠ fields and the distops package to the ⁠LinkingTo:⁠ field. It also adds the ⁠SystemRequirements: GNU make⁠ field. It then creates the NAMESPACE file adding the importFrom() directives for the Rcpp and RcppParallel packages and the useDynLib() directive for packages with compiled code. It finally creates the src/Makevars and src/Makevars.win files with the appropriate compilation flags.

Usage

use_distops()

Value

Nothing.

Examples

use_distops()