Learn R Programming

cheapr (version 1.1.0)

recycle: Recycle objects to a common size

Description

A convenience function to recycle R objects to either a common or specified size.

Usage

recycle(..., length = NULL)

Value

A list of recycled R objects.

Arguments

...

Objects to recycle.

length

Optional length to recycle objects to.

Details

Data frames are recycled by recycling their rows.
recycle() is optimised to only recycle objects that need recycling.
NULL objects are ignored and not recycled or returned.

Examples

Run this code
library(cheapr)

recycle(Sys.Date(), 1:10)

# Any vectors of zero-length are all recycled to zero-length
recycle(integer(), 1:10)

# Data frame rows are recycled
recycle(sset(iris, 1:3), length = 3 * 3)

# To recycle list items, use `do.call()`
my_list <- list(from = 1L, to = 10L, by = seq(0.1, 1, 0.1))
do.call(recycle, my_list)

Run the code above in your browser using DataLab