Package iterators. December 12, 2017

Similar documents
foreach/iterators User s Guide

Writing Custom Iterators

Package clipr. June 23, 2018

Package imgur. R topics documented: December 20, Type Package. Title Share plots using the imgur.com image hosting service. Version 0.1.

Package datasets.load

Package crochet. January 8, 2018

Package MmgraphR. R topics documented: September 14, Type Package

Package ECctmc. May 1, 2018

Package itertools2. R topics documented: August 29, 2016

Package chunked. July 2, 2017

Package projector. February 27, 2018

Package lxb. R topics documented: August 29, 2016

Package future.apply

Package fastdummies. January 8, 2018

Package clustering.sc.dp

Package readobj. November 2, 2017

Package lvec. May 24, 2018

Package reval. May 26, 2015

Package CRF. February 1, 2017

Package linkspotter. July 22, Type Package

Package truncreg. R topics documented: August 3, 2016

Package fimport. November 20, 2017

Package narray. January 28, 2018

Package filematrix. R topics documented: February 27, Type Package

Package bisect. April 16, 2018

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package arulescba. April 24, 2018

Package Rtsne. April 14, 2017

Package pomdp. January 3, 2019

Package TSzip. February 15, 2013

Package rucrdtw. October 13, 2017

Package glinternet. June 15, 2018

Package fastrtext. December 10, 2017

Package lumberjack. R topics documented: July 20, 2018

Package logitnorm. R topics documented: February 20, 2015

Package combiter. December 4, 2017

Package apastyle. March 29, 2017

Package lhs. R topics documented: January 4, 2018

Package fasttextr. May 12, 2017

Package calibrar. August 29, 2016

Package table1. July 19, 2018

Package RPostgres. December 6, 2017

Package LaF. November 20, 2017

Package ECOSolveR. February 18, 2018

Package Rspc. July 30, 2018

Package lmesplines. R topics documented: February 20, Version

Package qap. February 27, Index 5. Solve Quadratic Assignment Problems (QAP)

Package repec. August 31, 2018

Package slam. December 1, 2016

Package embed. November 19, 2018

Package flsa. February 19, 2015

Package nmslibr. April 14, 2018

Package stacomirtools

Package iotools. R topics documented: January 25, Version Title I/O Tools for Streaming

Package textrank. December 18, 2017

Package Rdrools. July 22, 2017

Package spark. July 21, 2017

Package sfc. August 29, 2016

Package svd. R topics documented: September 26, 2017

Package raker. October 10, 2017

Package QCAtools. January 3, 2017

Package bigreadr. R topics documented: August 13, Version Date Title Read Large Text Files

Package zebu. R topics documented: October 24, 2017

Package kirby21.base

Package localsolver. February 20, 2015

Package Rglpk. May 18, 2017

Package tibble. August 22, 2017

Package stacomirtools

Package regexselect. R topics documented: September 22, Version Date Title Regular Expressions in 'shiny' Select Lists

Package CatEncoders. March 8, 2017

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package catenary. May 4, 2018

Package slam. February 15, 2013

Package JBTools. R topics documented: June 2, 2015

Package labelvector. July 28, 2018

Package furrr. May 16, 2018

Package biganalytics

Package wikitaxa. December 21, 2017

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

Package rferns. November 15, 2017

Package farver. November 20, 2018

Package knitlatex. August 29, 2016

Package RPostgres. April 6, 2018

Package MDSGUI. February 19, 2015

Package Numero. November 24, 2018

Package lpsymphony. February 6, 2018

Package exporkit. R topics documented: May 5, Type Package Title Expokit in R Version Date

Package nonlinearicp

Package fgpt. February 19, 2015

Package CuCubes. December 9, 2016

Package profvis. R topics documented:

Package rbraries. April 18, 2018

Package comparedf. February 11, 2019

Package SingleCellExperiment

Package orloca. April 21, Type Package Depends methods, png, ucminf Suggests grdevices, graphics, knitr VignetteBuilder knitr

Package sgmcmc. September 26, Type Package

Package datapasta. January 24, 2018

Package RPresto. July 13, 2017

Package vinereg. August 10, 2018

Package RSNPset. December 14, 2017

Transcription:

Type Package Title Provides Iterator Construct for R Version 1.0.9 Package iterators December 12, 2017 Support for iterators, which allow a programmer to traverse through all the elements of a vector, list, or other collection of data. Depends R (>= 2.5.0), utils Suggests RUnit License Apache License (== 2.0) Author Rich Calaway [cre], Revolution Analytics [aut, cph], Steve Weston [aut] Maintainer Rich Calaway <richcala@microsoft.com> Repository CRAN Repository/R-Forge/Project foreach Repository/R-Forge/Revision 31 Repository/R-Forge/DateTimeStamp 2017-12-08 23:08:19 Date/Publication 2017-12-12 15:26:15 UTC NeedsCompilation no R topics documented: iterators-package...................................... 2 iapply............................................ 2 icount............................................ 3 idiv............................................. 4 iread.table.......................................... 5 ireadlines.......................................... 5 irnorm............................................ 6 isplit............................................. 7 iter.............................................. 8 nextelem.......................................... 9 1

2 iapply Index 11 iterators-package The Iterators Package Details The iterators package provides tools for iterating over various R data structures. Iterators are available for vectors, lists, matrices, data frames, and files. By following very simple conventions, new iterators can be written to support any type of data source, such as database queries or dynamically generated data. Further information is available in the following help topics: iter nextelem icount idiv ireadlines Generic function used to create iterator objects. Generic function used to get the next element of a iterator. A function used to create a counting iterator. A function used to create a number dividing iterator. A function used to create a file reading iterator. For a complete list of functions with individual help pages, use library(help="iterators"). iapply Array/Apply Iterator Returns an iterator over an array, which iterates over the array in much the same manner as the apply function. iapply(x, MARGIN) X MARGIN the array to iterate over. a vector of subscripts. 1 indicates the first dimension (rows), 2 indicates the second dimension (columns), etc. The apply iterator.

icount 3 See Also apply a <- array(1:8, c(2, 2, 2)) # iterate over all the matrices it <- iapply(a, 3) as.list(it) # iterate over all the columns of all the matrices it <- iapply(a, c(2, 3)) as.list(it) # iterate over all the rows of all the matrices it <- iapply(a, c(1, 3)) as.list(it) icount Counting Iterators Returns an iterator that counts starting from one. icount(count) icountn(vn) count vn number of times that the iterator will fire. If not specified, it will count forever. vector of counts. The counting iterator. # create an iterator that counts from 1 to 3. it <- icount(3) try() # expect a StopIteration exception

4 idiv idiv Dividing Iterator Returns an iterator that returns pieces of numeric value. idiv(n,..., chunks, chunksize) n... unused. chunks chunksize number of times that the iterator will fire. If not specified, it will count forever. the number of pieces that n should be divided into. This is useful when you know the number of pieces that you want. If specified, then chunksize should not be. the maximum size of the pieces that n should be divided into. This is useful when you know the size of the pieces that you want. If specified, then chunks should not be. The dividing iterator. # divide the value 10 into 3 pieces it <- idiv(10, chunks=3) try() # expect a StopIteration exception # divide the value 10 into pieces no larger than 3 it <- idiv(10, chunksize=3) try() # expect a StopIteration exception

iread.table 5 iread.table Iterator over Rows of a Data Frame Stored in a File Returns an iterator over the rows of a data frame stored in a file in table format. It is a wrapper around the standard read.table function. iread.table(file,..., verbose=false) Note file the name of the file to read the data from.... all additional arguments are passed on to the read.table function. See the documentation for read.table for more information. verbose The file reading iterator. logical value indicating whether or not to print the calls to read.table. In this version of iread.table, both the read.table arguments header and row.names must be specified. This is because the default values of these arguments depend on the contents of the beginning of the file. In order to make the subsequent calls to read.table work consistently, the user must specify those arguments explicitly. A future version of iread.table may remove this requirement. See Also read.table ireadlines Iterator over Lines of Text from a Connection Returns an iterator over the lines of text from a connection. It is a wrapper around the standard readlines function. ireadlines(con, n=1,...)

6 irnorm con n See Also a connection object or a character string. integer. The maximum number of lines to read. Negative values indicate that one should read up to the end of the connection. The default value is 1.... passed on to the readlines function. The line reading iterator. readlines # create an iterator over the lines of COPYING it <- ireadlines(file.path(r.home(), 'COPYING')) irnorm Random Number Iterators These function returns an iterators that return random numbers of various distributions. Each one is a wrapper around a standard R function. irnorm(..., count) irunif(..., count) irbinom(..., count) irnbinom(..., count) irpois(..., count) count number of times that the iterator will fire. If not specified, it will fire values forever.... arguments to pass to the underlying rnorm function. An iterator that is a wrapper around the corresponding random number generator function.

isplit 7 # create an iterator that returns three random numbers it <- irnorm(1, count=3) try() # expect a StopIteration exception isplit Split Iterator Returns an iterator that divides the data in the vector x into the groups defined by f. isplit(x, f, drop=false,...) x vector or data frame of values to be split into groups. f a factor or list of factors used to categorize x. drop See Also... current ignored. The split iterator. split logical indicating if levels that do not occur should be dropped. x <- rnorm(200) f <- factor(sample(1:10, length(x), replace=true)) it <- isplit(x, f) expected <- split(x, f) for (i in expected) { actual <- stopifnot(actual$value == i) }

8 iter iter Iterator Factory Functions iter is a generic function used to create iterator objects. 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 by chunksize checkfunc recycle an object from which to generate an iterator. how to iterate. the number of elements of by to return with each call to nextelem. a function which, when passed an iterator value, return TRUE or FALSE. If FALSE, the value is skipped in the iteration. a boolean describing whether the iterator should reset after running through all it s values.... additional arguments affecting the iterator. The iterator. # a vector iterator i1 <- iter(1:3) nextelem(i1)

nextelem 9 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) nextelem Get Next Element of Iterator nextelem is a generic function used to produce values. If a checkfunc was specified to the constructor, the potential iterated values will be passed to the checkfunc until the checkfunc returns TRUE. When the iterator has no more values, it calls stop with the message StopIteration. nextelem(obj,...) ## S3 method for class 'containeriter' nextelem(obj,...) ## S3 method for class 'funiter' nextelem(obj,...) obj an iterator object.... additional arguments that are ignored.

10 nextelem The value. it <- iter(c('a', 'b', 'c')) print() print() print()

Index Topic methods iter, 8 nextelem, 9 Topic package iterators-package, 2 Topic utilities iapply, 2 icount, 3 idiv, 4 iread.table, 5 ireadlines, 5 irnorm, 6 isplit, 7 apply, 3 iapply, 2 icount, 3 icountn (icount), 3 idiv, 4 irbinom (irnorm), 6 iread.table, 5 ireadlines, 5 irnbinom (irnorm), 6 irnorm, 6 irpois (irnorm), 6 irunif (irnorm), 6 isplit, 7 iter, 8 iterators (iterators-package), 2 iterators-package, 2 nextelem, 9 read.table, 5 readlines, 6 split, 7 11