the butler package -...
TRANSCRIPT
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
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 = "")
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
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
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
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
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
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
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
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
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]>
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
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
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
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", ...)
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
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.
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
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
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]>
20 throw_assert_error
Examples
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