Basically base::source()
, but prepending the library path with a
touchstone library and running the script in a temp directory to avoid
git operations like checking out different branches to interfere with the
script execution (as running the script changes itself through git checkout).
run_script(
path = "touchstone/script.R",
branch = branch_get_or_fail("GITHUB_HEAD_REF")
)
The script to run. It must fulfill the requirements of a touchstone_script.
The branch that corresponds to the library that should be prepended
to the library path when the script at path
is executed, see 'Why this
function?' below.
The same as base::source()
, which inherits from base::withVisible()
, i.e.
a list with value
and visible
(invisibly).
You can use activate()
to setup the environment to interactively run your
script, as there are some adjustments needed to mirror the Github Action
environment.
In a GitHub Action workflow, the environment variables GITHUB_BASE_REF
and
GITHUB_HEAD_REF
denote the target and source branch of the pull request -
and these are default arguments in benchmark_run()
(and other functions
you probably want to call in your benchmarking script) to determinate the
branches to use.
For isolation, {touchstone} does not allow the benchmarked package to be
installed in the global package library, but only in touchstone libraries, as
asserted with assert_no_global_installation()
. However, this also implies
that the package is not available in the touchstone script outside of
benchmark runs (i.e. outside of benchmark_run()
. We sometimes still
want to call that package to prepare a benchmarking run though. To
allow this, we prepend a touchstone library location that
contains the installed benchmarked package for set-up tasks, and temporarily
remove it during benchmarking with benchmark_run()
so only one
touchstone library is on the library path at any time.
if (FALSE) { # \dontrun{
# assuming you want to compare the branch main with the branch devel
if (rlang::is_installed("withr")) {
withr::with_envvar(
c("GITHUB_BASE_REF" = "main", "GITHUB_HEAD_REF" = "devel"),
run_script("touchstone/script.R")
)
}
} # }