the butler package -...

21
The butler Package September 2, 2005 Type Package Title Unit testing, profiling and benchmarking for R Version 0.3 Date 2005-08-22 Author Hadley Wickham <[email protected]> Maintainer Hadley Wickham <[email protected]> Description A package for testing, profiling and benchmarking your code. License MIT R topics documented: assert.equal ......................................... 2 assert.error ......................................... 2 assert.isS3class ....................................... 3 assert ............................................ 4 assert.warning ........................................ 4 assert.warning_error .................................... 5 benchmark .......................................... 6 benchmark2 ......................................... 6 displayCallNode ...................................... 7 expression.test ........................................ 8 getCalls ........................................... 8 getFirstCalls ......................................... 9 get_error ........................................... 9 get_warning ......................................... 10 is.all.equal .......................................... 11 is.assertError ........................................ 11 is.error ............................................ 12 is.positive.integer ...................................... 12 is.test ............................................ 13 nextCalls .......................................... 13 plot.call.tree ......................................... 14 plotCallNode ........................................ 15 print.benchmark ....................................... 15 print.call.tree ........................................ 16 1

Upload: vannhu

Post on 16-Aug-2019

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

The butler PackageSeptember 2, 2005

Type Package

Title Unit testing, profiling and benchmarking for R

Version 0.3

Date 2005-08-22

Author Hadley Wickham <[email protected]>

Maintainer Hadley Wickham <[email protected]>

Description A package for testing, profiling and benchmarking your code.

License MIT

R topics documented:

assert.equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2assert.error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2assert.isS3class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3assert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4assert.warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4assert.warning_error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5benchmark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6benchmark2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6displayCallNode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7expression.test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8getCalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8getFirstCalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9get_error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9get_warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10is.all.equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11is.assertError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11is.error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12is.positive.integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12is.test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13nextCalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13plot.call.tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14plotCallNode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15print.benchmark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15print.call.tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16

1

Page 2: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

2 assert.error

print.test.result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17stopwatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18test.result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19throw_assert_error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19

Index 21

assert.equal Assert equal

Description

Assert expected and actual are equal

Usage

assert.equal(expected, actual, msg = "")

Arguments

expected

actual

msg

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

assert.error Assert error

Description

Assert an error occured

Usage

assert.error(f, warning = "", msg = "")

Page 3: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

assert.isS3class 3

Arguments

f

warning

msg

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

assert.isS3class Assert is S3 class

Description

Assert argument is of given S3 class

Usage

assert.isS3class(obj, class, msg = "")

Arguments

obj

class

msg

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

Page 4: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

4 assert.warning

assert Assert

Description

Basic assert function that powers all others.

Usage

assert(condition, msg = "")

Arguments

condition condition to evaluation for truth

msg message to display if condition is false

should warnings be displayed

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

assert.warning Assert warning

Description

Assert that a warning occured

Usage

assert.warning(f, warning = "", msg = "")

Arguments

f

warning

msg

Details

Page 5: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

assert.warning_error 5

Author(s)

Hadley Wickham <[email protected]>

Examples

assert.warning_errorAssert warning or error

Description

Assert a warning of error occured

Usage

assert.warning_error(w, warning = "", msg = "")

Arguments

w

warning

msg

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

Page 6: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

6 benchmark2

benchmark Benchmark

Description

Compare the performance of different functions

Usage

benchmark(..., reps = 10)

Arguments

... functions to compare, make sure to name them (see example)

reps number of reps of each function to run

Details

@arguments functions to compare, make sure to name them (see example) @arguments number ofreps of each function to run @keyword debugging

Author(s)

Hadley Wickham <[email protected]>

Examples

mean1 = function() {x <- rnorm(1000); mean(x);}mean2 = function() {x <- rnorm(1000); sum(x) / length(x);}mean3 = function() {x <- rnorm(1000); total=0;for(i in 1:length(x)) {total <- total + x[i]}; total/length(x);}mt = benchmark(mean=mean1,sum=mean2,loop=mean3, reps=1000)print(mt)

benchmark2 Benchmark2

Description

An extension to benchmark which allows you to specify a (minimum) time for the functions to run

Usage

benchmark2(..., time = 3, reps = 10)

Arguments

... functions to compare, make sure to name them (see example)

time (minimum) time, in seconds, to run for

reps number of reps to run between checking time

Page 7: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

displayCallNode 7

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

displayCallNode Display call node

Description

@keyword debugging

Usage

displayCallNode(calls, level, value, depth, mintime)

Arguments

calls

level

value

depth

mintime

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

Page 8: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

8 getCalls

expression.test Expression test.

Description

Run test and display status

Usage

expression.test(expression, print=TRUE)

Arguments

expression expression to test

print print results?

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

getCalls Get calls

Description

Get all calls at a given level of the call stack

Usage

getCalls(calls, level, value)

Arguments

calls list of calls

level level of call stack

value function name

Details

Page 9: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

getFirstCalls 9

Author(s)

Hadley Wickham <[email protected]>

Examples

getFirstCalls Get first call

Description

@keyword debugging

Usage

getFirstCalls(calls, level)

Arguments

calls

level

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

get_error Get error

Description

Collect any errors created when running function

Usage

get_error(x)

Arguments

x

Page 10: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

10 get_warning

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

get_warning Get warning

Description

Collect any warnings created when running function

Usage

get_warning(x)

Arguments

x

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

Page 11: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

is.all.equal 11

is.all.equal Is all equal

Description

Are x and y equal

Usage

is.all.equal(x,y)

Arguments

x

y

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

is.assertError Is assert error?

Description

Is x an assertion error?

Usage

is.assertError(x)

Arguments

x

Details

Author(s)

Hadley Wickham <[email protected]>

Page 12: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

12 is.positive.integer

Examples

is.error Is error?

Description

Is x an assertion error?

Usage

is.error(x)

Arguments

x

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

is.positive.integeris.positive.integer

Description

Converience function for determining if x is a positive integer

Usage

is.positive.integer(x)

Arguments

x object to test

Details

Page 13: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

is.test 13

Author(s)

Hadley Wickham <[email protected]>

Examples

is.test Is this expression a test?

Description

Determine whether expression is a test and should be run when "test"-ing a file

Usage

is.test(expression)

Arguments

expression expression to test

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

nextCalls Get next call

Description

@keyword debugging

Usage

nextCalls(calls, level, value)

Arguments

calls

level

value

Page 14: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

14 plot.call.tree

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

plot.call.tree Plot call tree

Description

Attractively plot call tree

Usage

plot.call.tree(x, startlevel = 1, depth = 5, mintime = 2, ...)

Arguments

x

startlevel

depth

mintime

...

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

Page 15: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

plotCallNode 15

plotCallNode Plot call node

Description

Recursively function that powers plot.call.tree

Usage

plotCallNode(calls, level, value, start, end, mintime, startlevel, depth)

Arguments

calls

level

value

start

end

mintime

startlevel

depth

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

print.benchmark Print benchmark

Description

Print nicely formatted benchmark results

Usage

print.benchmark(x, type="total", ...)

Page 16: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

16 print.call.tree

Arguments

x benchmark object to display

type time to display (one of system, user or total)

... required to match generic

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

print.call.tree Print call tree

Description

Attractively print call tree

Usage

print.call.tree(x, startlevel = 3, depth = 8, mintime = 2, ...)

Arguments

x

startlevel

depth

mintime

...

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

Page 17: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

print.test.result 17

print.test.result Print test result

Description

Usage

print.test.result(x, ...)

Arguments

x

...

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

stopwatch Stop watch

Description

Profile the performance of function call.

Usage

stopwatch(f, reps = 2, interval = 0.02)

Arguments

f function to profile

reps number of times to run

interval interval between samples (in seconds)

Details

Results can be display nicely using either plot or print.

Page 18: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

18 test

Value

call tree

Author(s)

Hadley Wickham <[email protected]>

See Also

print.call.tree , plot.call.tree

Examples

test Test.

Description

Run all tests in given file and return results

Usage

test(path, print=TRUE)

Arguments

path path to file

print

Details

Displays status for each test as run and then reports particular errors ...F..E.. 8/10 successful, thenreport errors

Author(s)

Hadley Wickham <[email protected]>

Examples

Page 19: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

test.result 19

test.result Eval expression and return list with errors, warnings and the deparsedexpression

Description

@keyword debugging

Usage

test.result(expression)

Arguments

expression

Details

Author(s)

Hadley Wickham <[email protected]>

Examples

throw_assert_error Throw assert error

Description

Equivalent of stop(msg) but classed so that other methods can recognise it

Usage

throw_assert_error(msg)

Arguments

msg error message to display

Details

Author(s)

Hadley Wickham <[email protected]>

Page 20: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

20 throw_assert_error

Examples

Page 21: The butler Package - ftp.uni-bayreuth.deftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/butler.pdfRun test and display status Usage expression.test(expression, print=TRUE) Arguments

Index

∗Topic debuggingassert , 3assert.equal , 1assert.error , 2assert.isS3class , 2assert.warning , 4assert.warning_error , 4benchmark , 5benchmark2 , 6displayCallNode , 6expression.test , 7get_error , 9get_warning , 9getCalls , 8getFirstCalls , 8is.all.equal , 10is.assertError , 11is.error , 11is.positive.integer , 12is.test , 12nextCalls , 13plot.call.tree , 13plotCallNode , 14print.benchmark , 15print.call.tree , 15print.test.result , 16stopwatch , 17test , 17test.result , 18throw_assert_error , 19

assert , 3assert.equal , 1assert.error , 2assert.isS3class , 2assert.warning , 4assert.warning_error , 4

benchmark , 5benchmark2 , 6

displayCallNode , 6

expression.test , 7

get_error , 9get_warning , 9getCalls , 8getFirstCalls , 8

is.all.equal , 10is.assertError , 11is.error , 11is.positive.integer , 12is.test , 12

nextCalls , 13

plot.call.tree , 13, 17plotCallNode , 14print.benchmark , 15print.call.tree , 15, 17print.test.result , 16

stopwatch , 17

test , 17test.result , 18throw_assert_error , 19

21