Description Usage Arguments Value Author(s) Examples
Add a viewer to an iteration, for monitoring progress. Argument "fun" must be a function with at most two arguments. It will be passed the current value and the iteration number. Some default viewing functions are already defined like "print".
1 |
fun |
a viewer function |
every |
frequency: run every k iteration (default 1, meaning at every iteration) |
print.iter |
print iteration number |
used for side effects
Simon Barthelme
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | f <- function(x) x/2
g <- fp(f)
(g+viewer(print))(.1)
# Now print only after 10 iterations
(g+viewer(print,every=10))(3)
# Print iteration number
(g+viewer(print,every=5,TRUE))(3)
# Define custom viewer:
v = function(x) print(x,digits=2)
(g+viewer(v,every=5,TRUE))(3)
v2 = function(x,ind) sprintf("At iteration %i. Current value %.3f",ind,x) %>% print
(g+viewer(v2,every=5))(3)
#You can have multiple viewers, running at different frequencies
v1 = function(x,ind) sprintf("At iteration %i",ind)%>%print
(g+viewer(v1)+viewer(v2,every=5))(3)
#You can also use plotting
x0 <- rnorm(40)
plot(x0)
v <- function(x) points(x,col="grey")
(g+viewer(v))(x0)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.