restrict_array: Restrict (or permute) an array.

Description Usage Arguments Details Value

View source: R/restrict_array.R

Description

This function will restrict an array based upon a specified subset of its dimension-names, without any need for the user to worry about how these dimension-names are positioned within the array. However, if the user desires that the resulting array should have the specified order on the dimension-names, then the argument .permute can be set to TRUE in order to achieve that result.

Usage

1
2
restrict_array(.arr, .restrict, .drop = FALSE, .never_drop = NULL,
  .keep_attributes = TRUE, .permute = FALSE)

Arguments

.arr

The array we want to restrict. The code in its present incarnation requires an array with a full set of unique dimension-names, although I suppose it could be possible to extend to a case where the dimension-names are missing too.

.restrict

A named list that collects the arguments to be used in the restriction, i.e. the names should correspond to names of the dimension-names, and the values should specify a subset (or a permutation, if you are so inclined) of the dimension-names.

.drop

A logical argument, default value FALSE, that decides whether or not dimensions are allowed to drop.

.never_drop

A character vector to be used if .drop is TRUE, but some dimensions should be protected. The default value NULL does nothing, whereas the argument will be ignored if .drop is FALSE.

.keep_attributes

A logical argument, default value TRUE, that decides whether or not attributes should be kept after the restriction. Note that relevant class attributes are kept by default, and that dim and dimnames must be as specified by the restriction.

.permute

A logical argument, default value FALSE, that will decide whether or not the dimensions of the final array should be adjusted to one used by .restrict.

Details

Arrays are awesome, but it can alas be agonising to keep track of the dimension-names. This function frees the user from such frustrations.

Value

The result will depend on how .sub_arr and .arr is related. If the dimension-names of .sub_arr is contained in those of .arr, but its dimension is in fact smaller, then the result will be that .arr will be filled with copies of .sub_arr along the unspecified dimensions. If the dimensions are equal, then only those components in .arr that directly match the dimension-names of .sub_arr will be affected.


LAJordanger/leanRcoding documentation built on Feb. 27, 2020, 4:42 p.m.