store: Store intermediate iterations

Description Usage Arguments Value Functions Author(s) See Also Examples

Description

Store intermediate values in a function iteration. Argument "fun" must be a function with at most two arguments. It will be passed the current value and the iteration number, and it must return an object that will be stored. See examples

Usage

1
2
3
store(fun, every = 1)

stored(x)

Arguments

fun

a function

every

frequency: run every k iteration (default 1, meaning at every iteration)

Value

used for side effects

Functions

Author(s)

Simon Barthelme

See Also

viewer,stored

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
f <- function(x) x/2
g <- iter(f)+store(function(x) x)
res <- g(3,5)
stored(res) #The result of 5 iterations, as a vector
#Store more info:
st <- function(x,ind) list(value=x,iter=ind)
res <- (iter(f)+store(st))(3,5)
stored(res) ## We now have a list of lists
#To extract elements, use map_ functions from package purrr
stored(res) %>% purrr::map_int("iter")
stored(res) %>% purrr::map_dbl("value")
stored(res) %>% purrr::map_df(identity)
#Store a summary
st <- function(x,ind) list(mvalue=mean(x),iter=ind)
g <- iter(f)+store(st)
g(rnorm(10),5) %>% stored %>% purrr::map_df(identity)

dahtah/fixedpoints documentation built on May 14, 2019, 3:25 p.m.