Description Details Value Terminology Methods Examples
Experiment
Experiment
Methods
control(...)
control code block
candidate(...)
candidate code block
run(...)
execute code, runs call_block()
, then do_comparison()
...
: pass on parameters through call_block()
to
callr::r()
(wait=TRUE
) or callr::r_bg()
(wait=FALSE
)
call_block()
execute code, and collect timing data
do_comparison()
mostly an internal fxn, run after call_block
result()
fetch the result (named list)
publish(browse = TRUE)
publish results. creates an html file. if browse=TRUE
the file opens in your default browser. if browse=FALSE
you get a file path.
diff()
compare results by "diffing" in the R console. used inside of publish() to prepare diffs. different diff representations for different object types:
numeric/integer: take difference between 2, or matrix comparing > 2 results
character/factor: highlight differences in strings, like git diffs
data.frame/matrix: use visdat
images: use vdiffr
list: not sure how to do this
environments: not sure how to do this
compare(x = NULL)
set a custom comparison function, must result in a single boolean fun: a function
an object of class Experiment
The control
block is the control, the current state of the code.
The candidate
block is the candidate, or the new version of the code
you want to compare to the control.
new()
Experiment$new(name, error_on_mismatch = FALSE, wait = TRUE, progress = FALSE)
name
The name of the experiment
error_on_mismatch
(logical) whether to error on mismatch of
results. default: FALSE
wait
(logical) wait for code to execute. if FALSE
, code is run in the
background, and you have to run $collect()
to collect results.
default: TRUE
progress
(logical) whether to turn on progress information or not,
default: TRUE
(IGNORED RIGHT NOW)
print()
Experiment$print(...)
call_block()
Experiment$call_block(...)
status()
Experiment$status()
collect()
Experiment$collect()
control()
Experiment$control(...)
candidate()
Experiment$candidate(...)
run()
Experiment$run(...)
compare()
Experiment$compare(x = NULL)
do_comparison()
Experiment$do_comparison()
result()
Experiment$result()
publish()
Experiment$publish(browse = TRUE)
diff()
Experiment$diff()
clone()
The objects of this class are cloneable with this method.
Experiment$clone(deep = FALSE)
deep
Whether to make a deep clone.
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | library(scientist)
# basic eg
res <- Experiment$new(name = "jane")
res$control({
x = 5
x^2
})
res$candidate({
y = 5
y^3
})
res
res$run()
res$control_result
res$candidate_results
res$result()
# publish results
res$publish()
# many candidates
res <- Experiment$new(name = "doe")
res
res$control(stuff = {
Sys.sleep(2)
x = 5
x^2
})
res$candidate(foo = {
Sys.sleep(2)
y = 5
y^3
}, bar = {
Sys.sleep(2)
w = 1000
(w - 20) / 34
})
res
res$run()
res$control_result
res$candidate_results
res$result()
res$times
# publish results
res$publish()
# raise errors when the control and experiment do no match
res <- Experiment$new(name = "treetest", error_on_mismatch = TRUE)
res$control({
x = 5
x^2
})
res$candidate({
y = 5
y^3
})
res
## Not run: res$run()
# if not waiting, run $status() and $collect()
res <- Experiment$new(name = "junipers", wait = FALSE)
res$control({
x = 5
x^2
})
res$candidate({
y = 5
y^3
})
## Not run: res$status()
res$run()
res
res$status()
## Not run: res$collect()
res$result()
# set explicit comparison
# FIXME: not working yet
# res <- Experiment$new(name = "jane")
# res$control({
# x = 5
# x^2
# })
# res$candidate({
# y = 5
# y^2
# })
# res$compare(function(control, candidate) {
# control/2 == candidate/1
# })
# res$run()
# res$result()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.