do: Do Things Repeatedly

View source: R/xdo.R View source: R/do.R View source: R/do.R

doR Documentation

Do Things Repeatedly

Description

do() provides a natural syntax for repetition tuned to assist with replication and resampling methods.

Number of iterations is capped at 2000 to prevent individual users from hogging server computation time. Additional details about the do function can be found in the do package documentation

Number of iterations is capped at 500 to prevent individual users from hogging server computation time. Additional details about the do function can be found in the do package documentation

Usage

do(N)

do.numeric(object, ...)

do.default(object, ...)

Do(n = 1L, cull = NULL, mode = "default", algorithm = 1, parallel = TRUE)

## S3 method for class 'repeater'
print(x, ...)

## S4 method for signature 'repeater,ANY'
e1 * e2

do(N)

do(N)

Arguments

object

an object

...

additional arguments

n

number of times to repeat

cull

function for culling output of objects being repeated. If NULL, a default culling function is used. The default culling function is currently aware of objects of types lme, lm, htest, table, cointoss, and matrix.

mode

target mode for value returned

algorithm

a number usd to select the algorithm used. Currently numbers below 1 use an older algorithm and numbers >=1 use a newer algorithm which is faster in some situations.

parallel

a logical indicating whether parallel computation should be attempted using the parallel package (if it is installed and loaded).

x

an object created by do.

e1

an object (in cases documented here, the result of running do)

e2

an object (in cases documented here, an expression to be repeated)

Value

do returns an object of class repeater which is only useful in the context of the operator *. See the examples.

A data frame of the values for the repeated function.

A data frame of the values for the repeated function.

Note

Find more examples, help and details at the help page for do in the mosaic package.

Find more examples, help and details at the help page for do in the mosaic package.

Note

do is a thin wrapper around Do to avoid collision with do from the dplyr package.

Author(s)

Daniel Kaplan (kaplan@macalaster.edu) and Randall Pruim (rpruim@calvin.edu)

See Also

replicate, set.rseed

Examples

do(3) * rnorm(1)
do(3) * "hello"
do(3) * 1:4
do(3) * mean(rnorm(25))
if (require(mosaicData)) {
  do(3) * lm(shuffle(height) ~ sex + mother, Galton)
  do(3) * anova(lm(shuffle(height) ~ sex + mother, Galton))
  do(3) * c(sample.mean = mean(rnorm(25)))
  set.rseed(1234)
  do(3) * tally( ~sex|treat, data=resample(HELPrct))
  set.rseed(1234)  # re-using seed gives same results again
  do(3) * tally( ~sex|treat, data=resample(HELPrct))
}
do(10) * sample(1:10, size=2)

do(10) * sample(1:10, size=2)


mobilizingcs/mobilizr documentation built on Feb. 17, 2024, 7:49 p.m.