chunk_data_ {utile.tools}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 = ', ')

[Package utile.tools version 0.3.0 Index]