Learn R Programming

utile.tools (version 0.2.8)

chunk_data_: 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)

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.

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.

Examples

Run this code
# 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 = ', ')

Run the code above in your browser using DataLab