From 0ac14048a8843923f136e9900c08ceb036e8312a Mon Sep 17 00:00:00 2001 From: Nick-Eagles Date: Wed, 31 Jul 2024 11:21:53 -0400 Subject: [PATCH] Fix a bug where 'array_submit' couldn't handle absolute paths to the script of interest --- R/array_submit.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/R/array_submit.R b/R/array_submit.R index 7d8fbcb..95cda38 100644 --- a/R/array_submit.R +++ b/R/array_submit.R @@ -223,17 +223,20 @@ array_submit <- function(name, task_ids = NULL, submit = FALSE, restore = TRUE, paste0("#SBATCH --array=", paste(task_ids, collapse = ","), "%\\1"), job_original ) - writeLines(job_new, con = paste0(name, ".sh")) + writeLines(job_new, con = sh_file) # Invoke (sbatch) the modified script if requested if (submit) { message(paste(Sys.time(), "Resubmitting the specified tasks.")) - system(sprintf("sbatch %s.sh", name)) + + # Some paths in the shell script are relative and we therefore must + # submit the script from the original directory + system(sprintf("cd %s; sbatch %s.sh", dirname(sh_file), name)) } # Restore the original script - if (restore) writeLines(job_original, con = paste0(name, ".sh")) + if (restore) writeLines(job_original, con = sh_file) # Return the path - return(invisible(paste0(name, ".sh"))) + return(invisible(sh_file)) }