Description Usage Arguments Value Examples
iter
is a generic function used to create iterator objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | iter(obj, ...)
## Default S3 method:
iter(obj, checkFunc=function(...) TRUE, recycle=FALSE,
...)
## S3 method for class 'iter'
iter(obj, ...)
## S3 method for class 'matrix'
iter(obj, by=c('column', 'cell', 'row'), chunksize=1L,
checkFunc=function(...) TRUE, recycle=FALSE, ...)
## S3 method for class 'data.frame'
iter(obj, by=c('column', 'row'),
checkFunc=function(...) TRUE, recycle=FALSE, ...)
## S3 method for class 'function'
iter(obj, checkFunc=function(...) TRUE,
recycle=FALSE, ...)
|
obj |
an object from which to generate an iterator. |
by |
how to iterate. |
chunksize |
the number of elements of |
checkFunc |
a function which, when passed an iterator value,
return |
recycle |
a boolean describing whether the iterator should reset after running through all it's values. |
... |
additional arguments affecting the iterator. |
The iterator.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # a vector iterator
i1 <- iter(1:3)
nextElem(i1)
nextElem(i1)
nextElem(i1)
# a vector iterator with a checkFunc
i1 <- iter(1:3, checkFunc=function(i) i %% 2 == 0)
nextElem(i1)
# a data frame iterator by column
i2 <- iter(data.frame(x=1:3, y=10, z=c('a', 'b', 'c')))
nextElem(i2)
nextElem(i2)
nextElem(i2)
# a data frame iterator by row
i3 <- iter(data.frame(x=1:3, y=10), by='row')
nextElem(i3)
nextElem(i3)
nextElem(i3)
# a function iterator
i4 <- iter(function() rnorm(1))
nextElem(i4)
nextElem(i4)
nextElem(i4)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.