The whirl package provide functionalities for executing scripts in batch and simultaneously getting a log from the individual executions. A log from script execution is in many pharmaceutical companies a GxP requirement, and the whirl package honors this requirement by generating a log that, among other things, contains information about:
And all this is wrapped into a nicely formatted html document that is easy to navigate.
# Install the released version from CRAN:
install.packages("whirl")
# Install the development version from GitHub:
::pak("NovoNordisk-OpenSource/whirl") pak
The main function in the whirl package is run()
which
takes an input
argument that defines the scripts to be
executed.
The simplest way is to provide the path to a single script:
library(whirl)
run("success.R")
#> ✔ success.R: Completed succesfully
It is also possible to run several scripts simultaneously:
<- run(c("success.R", "warning.R"), n_workers = 2)
result #> ✔ success.R: Completed succesfully
#> ⚠ warning.R: Completed with warnings
Here we are specifying that run()
can use up to two
simultaneous workers to execute the scripts, meaning that they will be
executed in parallel.
When using run()
the following files are created:
{script_name}_log.html
. See example_log.html
for an example of a simple log.summary.html
. See summary.html
for an example of a summary of the same log as above.Apart from this the function also returns a tibble
with
the status of the script execution similar to the content of the summary
above:
print(result)
#> # A tibble: 2 × 6
#> id tag script status result log_dir
#> <dbl> <chr> <chr> <chr> <list> <chr>
#> 1 1 <NA> /private/var/folders/fx/71by3f551qzb5… succe… <named list> /priva…
#> 2 2 <NA> /private/var/folders/fx/71by3f551qzb5… warni… <named list> /priva…
run()
also supports running scripts in several
sequential steps. This setup is very useful when your projects have
several steps that depends on each others output, and thereby need to be
executed in a specific order. The best way to implement this in your
project is use a configuration file for whirl. The configuration file is
a yaml
file that specifies each steps:
_whirl.yaml:
steps:
- name: "First step"
paths:
- "success.R"
- name: "Second step"
paths:
- "warning.R"
- "error.R"``
Here we are specifying that in the first step we run
succes.R
. And then when this step has been completed we
continue to running the scripts in the second steps.
<- run("_whirl.yaml", n_workers = 2)
result #> ✔ success.R: Completed succesfully
#> ⚠ warning.R: Completed with warnings
#> ✖ error.R: Completed with errors
print(result)
#> # A tibble: 3 × 6
#> id tag script status result log_dir
#> <dbl> <chr> <chr> <chr> <list> <chr>
#> 1 1 <NA> /private/var/folders/fx/71by3f551qzb5… succe… <named list> /priva…
#> 2 2 <NA> /private/var/folders/fx/71by3f551qzb5… warni… <named list> /priva…
#> 3 3 <NA> /private/var/folders/fx/71by3f551qzb5… error <named list> /priva…
For more information about how to customize the the execution and the logging for your needs see the following:
run()
: For further information on how to call it.vignette("whirl")
: For a more in depth explanation, and
more advanced usage.vignette("articles/example")
: With a simple example,
including the created log.