chunk_data_: Break data into chunks

chunk_data_R Documentation

Break data into chunks

Description

Creates a factory function which returns a different chunk of a given data object with each function call.

Usage

chunk_data_(x, size = 10, reverse = FALSE)

Arguments

x

A data frame or vector.

size

An integer. The number of items (e.g. rows in a tibble) that make up a given chunk. Must be a positive integer.

reverse

A logical. Calculate chunks from back to front.

Value

A factory function which returns a chunk of data from the provided object with each call. Once all data has been returned, function returns NULL perpetually.

Examples

# Create chunk factory function
chunked_data <- chunk_data_(mtcars, size = 6)

# Chunk #1 (rows 1-6)
paste0(rownames(chunked_data()), collapse = ', ')

# Chunk #2 (rows 7-12)
paste0(rownames(chunked_data()), collapse = ', ')

utile.tools documentation built on Feb. 16, 2023, 10:08 p.m.