-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwrap_examples.R
47 lines (42 loc) · 1.55 KB
/
wrap_examples.R
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
load_my_example_pkg <- function(pkg, recompile = TRUE, ...) {
if (!requireNamespace("devtools", quietly = TRUE)) {
stop("Package devtools must be installed to run unit tests.",
call. = FALSE)
}
path <- system.file(file.path('examples', pkg), package = 'RcppProgress')
devtools::load_all(path, quiet = TRUE, recompile = recompile, ...)
}
get_function_from_pkg <- function(pkg, fun) {
get(fun, getNamespace(pkg))
}
test_sequential <- function(max = 100, nb = 1000, display_progress= TRUE, ...) {
pkg <- 'RcppProgressExample'
load_my_example_pkg(pkg, ...)
fun <- get_function_from_pkg(pkg, 'test_sequential')
fun(max, nb, display_progress)
}
# R wrapper for the example function #2
test_multithreaded <- function(max = 100, nb = 1000, threads = 0,
display_progress = TRUE, ...)
{
pkg <- 'RcppProgressExample'
load_my_example_pkg(pkg, ...)
fun <- get_function_from_pkg(pkg, 'test_multithreaded')
fun(max, nb, threads, display_progress)
}
amardillo_multithreaded <- function(max = 100, nb = 1000, threads = 0,
display_progress = TRUE, ...)
{
testthat::skip_if_not_installed('RcppArmadillo')
pkg <- 'RcppProgressArmadillo'
load_my_example_pkg(pkg, ...)
fun <- get_function_from_pkg(pkg, 'test_multithreaded')
fun(max, nb, threads, display_progress)
}
eta_progress_bar <- function(max = 100, nb = 1000, display_progress = TRUE)
{
pkg <- 'RcppProgressETA'
load_my_example_pkg(pkg)
fun <- get_function_from_pkg(pkg, 'test_sequential')
fun(max, nb, display_progress)
}