inst/doc/Introduction.R

## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ---- include=FALSE-----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## -----------------------------------------------------------------------------
library(deflist)

square_fun <- function(i) i^2
square_deflist <- deflist(square_fun, len = 5)
square_deflist


## -----------------------------------------------------------------------------
# Access by index
square_deflist[[1]]
square_deflist[[2]]

# Access multiple elements
square_deflist[c(1, 3, 5)]

## -----------------------------------------------------------------------------
memoised_square_fun <- deflist(square_fun, len = 5, memoise = TRUE, cache = "memory")
memoised_square_fun

# Access an element multiple times
system.time({ for (i in 1:1000) memoised_square_fun[[1]] })

## -----------------------------------------------------------------------------

square_list <- as.list(square_deflist)
square_list


## -----------------------------------------------------------------------------
try(square_deflist[[1]] <- 0)

Try the deflist package in your browser

Any scripts or data that you put into this service are public.

deflist documentation built on April 27, 2023, 5:11 p.m.