diff --git a/DESCRIPTION b/DESCRIPTION index 9d5b429..465f199 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: whirl Title: Logging package -Version: 0.1.5.9000 +Version: 0.1.6 Authors@R: c( person("Aksel", "Thomsen", , "oath@novonordisk.com", role = c("aut", "cre")), person("Lovemore", "Gakava", , "lvgk@novonordisk.com", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 3541918..1667847 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,11 @@ -# whirl dev +# whirl 0.1.6 (2024-11-25) * Added support for logging of Python scripts with `run()`. * Improved unit tests for `run()` +* Fixing a bug where the queue was not returned correctly in some instances. +* Switched to using `Sys.glob()` instead of `utils::glob2rx()`. + +# whirl 0.1.5 (2024-11-21) +* Reducing the number of dependencies. # whirl 0.1.4 (2024-11-01) * Add `use_whirl()` utility function. diff --git a/R/enrich_input.R b/R/enrich_input.R index 5f5c640..440c18e 100644 --- a/R/enrich_input.R +++ b/R/enrich_input.R @@ -57,7 +57,7 @@ enrich_input <- function(input, steps = NULL, # Normalizing the paths and read regexp for (j in seq_along(paths)) { normalized <- unlist(lapply(paths[[j]], normalize_with_base, base = root_dir)) - paths[[j]] <- read_regexp(normalized) + paths[[j]] <- read_glob(normalized) } # If input include one or more directories diff --git a/R/internal_run.R b/R/internal_run.R index ca91738..88e941f 100644 --- a/R/internal_run.R +++ b/R/internal_run.R @@ -41,14 +41,10 @@ internal_run <- function(input, steps, queue, level, verbosity_level = verbosity_level) } else { # Execute the scripts - result <- queue$run(files) + queue$run(files) } } - if (exists("result")) { - invisible(result) - } - - + invisible(queue) } diff --git a/R/read_regexp.R b/R/read_glob.R similarity index 65% rename from R/read_regexp.R rename to R/read_glob.R index 93fd4f8..71781e5 100644 --- a/R/read_regexp.R +++ b/R/read_glob.R @@ -4,19 +4,17 @@ #' used as input these will be solved to the actual files matching the #' criteria. #' @noRd -read_regexp <- function(input) { + +read_glob <- function(input) { files_ <- lapply(input, function(x) { #If the file exist then return the path if (file.exists(x)) { return(x) } else { - #If the file does not exist then check if it is a regexp - regexp <- basename(x) |> - utils::glob2rx() - - files <- list.files(path = dirname(x), pattern = regexp, full.names = TRUE) + #If the file does not exist then check if it is a glob + files <- Sys.glob(x) if (length(files) == 0) { - cli::cli_abort("No files or folders for this path {x}") + cli::cli_alert_warning("No files or folders for this path {x}") } return(files) } diff --git a/inst/examples/demo/adam/adamprog_whirl.yaml b/inst/examples/demo/adam/adamprog_whirl.yaml new file mode 100644 index 0000000..50bc7e5 --- /dev/null +++ b/inst/examples/demo/adam/adamprog_whirl.yaml @@ -0,0 +1,6 @@ +steps: + - name: "Run adam mk400 programs" + paths: + - "mk400*.R" + + diff --git a/tests/testthat/scripts/_whirl_r_programs.yaml b/tests/testthat/scripts/_whirl_r_programs.yaml index 65c42d1..a42a206 100644 --- a/tests/testthat/scripts/_whirl_r_programs.yaml +++ b/tests/testthat/scripts/_whirl_r_programs.yaml @@ -1,4 +1,4 @@ steps: - name: "Run all R programs" paths: - - "*.r|R" + - "*.R" diff --git a/tests/testthat/test-examples.R b/tests/testthat/test-examples.R index 34a7502..133024a 100644 --- a/tests/testthat/test-examples.R +++ b/tests/testthat/test-examples.R @@ -10,9 +10,9 @@ test_that("All example scripts run with consistent output", { # Run all examples after in separate steps - res <- list.files() |> + res <- list(list.files(pattern = "*.yaml"), list.files(pattern = "*.R$")) |> as.list() |> - run() |> + run(n_workers = 2) |> expect_no_error() |> expect_no_warning() diff --git a/tests/testthat/test-internal_run.R b/tests/testthat/test-internal_run.R index 6500fd0..e413346 100644 --- a/tests/testthat/test-internal_run.R +++ b/tests/testthat/test-internal_run.R @@ -2,7 +2,7 @@ test_that("testing internal_run()", { # A config file - q <- whirl_queue$new() + q <- whirl_queue$new(n_workers = 2) test_script("_whirl.yaml") |> internal_run(steps = NULL, level = 1, queue = q) |> diff --git a/tests/testthat/test-read_regexp.R b/tests/testthat/test-read_glob.R similarity index 70% rename from tests/testthat/test-read_regexp.R rename to tests/testthat/test-read_glob.R index 433f313..9eea810 100644 --- a/tests/testthat/test-read_regexp.R +++ b/tests/testthat/test-read_glob.R @@ -1,25 +1,22 @@ -test_that("read_regexp() finds the right files", { +test_that("testing read_glob()", { # A single file - test_script("success.R") |> - read_regexp() |> + read_glob() |> expect_equal(test_script("success.R")) # All R files in a directory - test_script("") |> file.path("*.R") |> - read_regexp() |> + read_glob() |> expect_match("\\.R$") |> length() |> expect_gt(1) # Error when file does not exist - test_script("") |> file.path("fake_program.R") |> - read_regexp() |> - expect_error() + read_glob() |> + expect_message() }) diff --git a/tests/testthat/test-run.R b/tests/testthat/test-run.R index 78364c0..34c3b2f 100644 --- a/tests/testthat/test-run.R +++ b/tests/testthat/test-run.R @@ -31,7 +31,7 @@ test_that("Run single python script", { test_that("Run multiple R scripts", { res <- test_script(c("success.R", "warning.R", "error.R")) |> - run() |> + run(n_workers = 2) |> expect_no_error() res[["status"]] |> @@ -56,7 +56,7 @@ test_that("Run multiple R scripts", { test_that("Run multiple python scripts", { res <- test_script(c("py_success.py", "py_warning.py", "py_error.py")) |> - run() |> + run(n_workers = 2) |> expect_no_error() res[["status"]] |> @@ -81,7 +81,7 @@ test_that("Run multiple python scripts", { test_that("Run yaml config file", { res <- test_script("_whirl.yaml") |> - run() |> + run(n_workers = 2) |> expect_no_error() }) diff --git a/vignettes/whirl.Rmd b/vignettes/whirl.Rmd index 7a8c1e7..fb916b4 100644 --- a/vignettes/whirl.Rmd +++ b/vignettes/whirl.Rmd @@ -39,14 +39,14 @@ The location of the summary file can be controlled with the `summary_file` argum ```{r} # Execution of all R files in a specific directory run( - input = "path/to/directory/*.(r|R)", + input = "path/to/directory/*.R", n_workers = 4, summary_file = "path/to/summary" ) # Execution of all R files starting with "mk200" in a specific directory run( - input = "path/to/directory/mk200*.(r|R)", + input = "path/to/directory/mk200*.R", n_workers = 8, summary_file = "path/to/summary" )