Skip to content

Commit 70ba37e

Browse files
add option to use a custom lockfile with renv_tmpl
1 parent ef242f2 commit 70ba37e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

R/slurmworkflow_helpers.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ swf_renv_sbatch_opts <- function() {
127127
#' the project is not following the right branch, this step will error.
128128
#' @param setup_lines (optional) a vector of bash lines to be run first.
129129
#' This can be used to load the required modules (like R, python, etc).
130+
#' @param lockfile (optional) path to an alternative lockfile to restore
130131
#'
131132
#' @return a template function to be used by \code{add_workflow_step}
132133
#'
133134
#' @export
134-
step_tmpl_renv_restore <- function(git_branch, setup_lines = NULL) {
135+
step_tmpl_renv_restore <- function(git_branch, setup_lines = NULL, lockfile = NULL) {
135136
instructions <- c(
136137
"CUR_BRANCH=$(git rev-parse --abbrev-ref HEAD)",
137138
paste0("if [[ \"$CUR_BRANCH\" != \"", git_branch, "\" ]]; then"),
@@ -141,10 +142,16 @@ step_tmpl_renv_restore <- function(git_branch, setup_lines = NULL) {
141142
"fi",
142143
"git pull",
143144
"Rscript -e \"renv::init(bare = TRUE, load = FALSE)\"",
144-
"Rscript -e \"renv::restore()\""
145+
"Rscript -e \"renv::restore(lockfile = lockfile)\""
145146
)
147+
if (is.null(lockfile)) {
148+
instructions <- c(instructions, "Rscript -e \"renv::restore()\"")
149+
} else {
150+
instructions <- c(instructions,
151+
"Rscript -e \"renv::restore(lockfile = lockfile)\"")
152+
}
153+
146154
instructions <- slurmworkflow::helper_use_setup_lines(instructions, setup_lines)
147155

148156
slurmworkflow::step_tmpl_bash_lines(instructions)
149157
}
150-

0 commit comments

Comments
 (0)