split_vector: Split a vector into smaller pieces

Description Usage Arguments Value

View source: R/split_vector.R

Description

This function chops a vector into a given number of pieces, and it tries to do this by making them as similar in length as possible. This function is used when splitting an array into chunks in order for foreach to work upon them in parallel, and it is also used in splitting that aims to avoid out-of-memory errors (due to large intermediate objects) by creating sizeable chunks that stays below a memory-limit. It does also allow additional stuff to be stored in the result, see details below.

Usage

1
2
3
split_vector(vec, pieces, allow_extra_pieces = FALSE,
  compute_name = NULL, subset_name = NULL, add_to_compute = NULL,
  position = 1)

Arguments

vec

The vector we want to split.

pieces

The number of chunks we want in the end.

allow_extra_pieces

Logical argument, default value FALSE. Use TRUE when this function is used as a tool for splitting up computations in order to get them below a critical threshold in relation to memory, in which case it's safer to allow pieces to take care of the remainder than to hope that it still should work. ## TASK: Explain this better later on.

compute_name

Use this to specify the name to be used in the compute-part of the resulting list. When the default NULL is used, a name will be created based on vec.

subset_name

Use this to specify the name to be used in the subset-part of the resulting list. When the default NULL is used, a name will be created based on vec.

add_to_compute

list, default NULL. Some functions might want more stuff in the compute-list, and this argument can then be used to add that stuff.

position

An integer, default value 1, that only should be used when add_to_compute is used. Use this argument to ensure that the splitting of the vector occurs at the desired position within the resulting compute-list, which might be desirable if e.g. array should be used to create a restricted array based on the splitting of a dimension vec.

Value

This function returns a list with three components: pieces, a vector that we want to loop over, and, subset and compute that respectively gives the arguments needed by the function 'restrict' (that also can do replacements) and the function that performs the computation of interest.


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