From 22fc229ac01c42d89c8a651a4e5c8a122a3a57a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Han=C3=9F?= Date: Thu, 3 Sep 2020 12:11:00 +0200 Subject: [PATCH 1/4] Adds missing R functions. Fixes #25 --- R/CxxFlags.R | 11 +++++++++++ R/wrap_examples.R | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 R/CxxFlags.R create mode 100644 R/wrap_examples.R diff --git a/R/CxxFlags.R b/R/CxxFlags.R new file mode 100644 index 0000000..1c1eea8 --- /dev/null +++ b/R/CxxFlags.R @@ -0,0 +1,11 @@ +CxxFlags <- function() +{ + path <- tools::file_path_as_absolute(base::system.file("include", package = "RcppProgress")) + if (.Platform$OS.type == "windows") { + path <- base::normalizePath(path) + if (grepl(" ", path, fixed = TRUE)) + path <- utils::shortPathName(path) + path <- gsub("\\\\", "/", path) + } + paste0("-I", path) +} \ No newline at end of file diff --git a/R/wrap_examples.R b/R/wrap_examples.R new file mode 100644 index 0000000..3c88208 --- /dev/null +++ b/R/wrap_examples.R @@ -0,0 +1,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) +} \ No newline at end of file From 439d43514f3289c71ca2426b3c48977046938cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Han=C3=9F?= Date: Thu, 3 Sep 2020 12:12:20 +0200 Subject: [PATCH 2/4] Remove source("wrap_examples.R") This gives a warning, It makes no sense to me and the tests are still passing. --- tests/testthat/test-pkg_examples.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/testthat/test-pkg_examples.R b/tests/testthat/test-pkg_examples.R index 6e0c5b1..f7d12dc 100644 --- a/tests/testthat/test-pkg_examples.R +++ b/tests/testthat/test-pkg_examples.R @@ -1,5 +1,3 @@ -source("wrap_examples.R") - context('RcppProgressExample sequential\n') .test_sequential <- function() { From 9e6c05e576d432aa482c63657651f173c0abc3bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Han=C3=9F?= Date: Thu, 3 Sep 2020 12:13:11 +0200 Subject: [PATCH 3/4] Un-commenting make test script --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8632337..cf31064 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ cache: packages pandoc: false -#before_script: -# - make tests +before_script: + - make tests r_github_packages: - jimhester/covr From 836a849718826e0b13bca029d04c122f9f2fba27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Han=C3=9F?= Date: Thu, 3 Sep 2020 15:20:52 +0200 Subject: [PATCH 4/4] Fixed return type --- R/CxxFlags.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/CxxFlags.R b/R/CxxFlags.R index 1c1eea8..f83fdc5 100644 --- a/R/CxxFlags.R +++ b/R/CxxFlags.R @@ -7,5 +7,5 @@ CxxFlags <- function() path <- utils::shortPathName(path) path <- gsub("\\\\", "/", path) } - paste0("-I", path) + cat(paste0("-I", path)) } \ No newline at end of file